package com.yuncheng.spcyApi.spcyService;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.spcyApi.config.SpcyMinioUtils;
import com.yuncheng.spcyApi.selectXzxkApi.bo.QyGjryBo;
import com.yuncheng.spcyApi.selectXzxkApi.constant.XzXkConstant;
import com.yuncheng.spcyApi.selectXzxkApi.vo.XzspXzxdrXdrryVo;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.bo.*;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.dto.*;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.mapper.*;
import com.yuncheng.spcyApi.selectXzxkApi.vo.XzspXzxdrJbxxVo;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.spcyApi.vo.common.Result;
import com.yuncheng.spcyApi.vo.common.StartEndDateVo;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import utils.DateConversionUtils;
import utils.LogUtils;
import utils.ObjectToMapUtils;
import utils.Util;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;

@Component(value = "spcyQyInfoService")
public class SpcyQyInfoService {
    private static final Logger log = LoggerFactory.getLogger(SpcyQyInfoService.class);

    @Resource
    @Lazy
    private ISpcyLogService spcyLogService;

    @Resource
    private IYcSysUserService sysUserService;

    @Resource
    private YcSysUserMapper ycSysUserMapper;

    @Resource
    private XzXkMapper xzXkMapper;

    @Resource
    @Lazy
    private SpcyQyZjxxMapper spcyQyZjxxMapper;

    @Resource
    @Lazy
    private SpcyQyYlgyssjMapper spcyQyYlgyssjMapper;

    @Resource
    @Lazy
    private SpcyQyScjlMapper spcyQyScjlMapper;

    @Resource
    @Lazy
    private SpcyQySccjMapper spcyQySccjMapper;

    @Resource
    @Lazy
    private SpcyQyWlmlMapper spcyQyWlmlMapper;

    @Resource
    private ISpcyQyJbxxService spcyQyJbxxService;

    @Resource
    private ISpcyQyWjjlService spcyQyWjjlService;

    @Resource
    private ISpcyQyWjmlService spcyQyWjmlService;

    @Resource
    private ISpcyQyCppcxxService spcyQyCppcxxService;

    @Resource
    private ISpcyQyGyyzService spcyQyGyyzService;

    @Resource
    private ISpcyQyJcxxService spcyQyJcxxService;

    @Resource
    private ISpcyQyPzjbxxService spcyQyPzjbxxService;

    @Resource
    private ISpcyQyQjyzService spcyQyQjyzService;

    @Resource
    private ISpcyQyQygjryxxService spcyQyQygjryxxService;

    @Resource
    private ISpcyQySbqrxxService spcyQySbqrxxService;

    @Resource
    private ISpcyQyYlgyssjService spcyQyYlgyssjService;

    @Resource
    private ISpcyQyWfwjjlService spcyQyWfwjjlService;

    @Resource
    private ISpcyQyRylxService spcyQyRylxService;

    @Resource
    private ISpcyQyBgkzService spcyQyBgkzService;

    @Resource
    @Lazy
    private ISpcyQyZjxxService spcyQyZjxxService;

    @Resource
    private ISpcyQySccjService spcyQySccjService;

    @Resource
    private ISpcyQySchjService spcyQySchjService;

    @Resource
    private ISpcyQySccjjlService spcyQySccjjlService;

    @Resource
    private ISpcyQyScjlService spcyQyScjlService;

    @Resource
    private ISpcyQyScjlgxService spcyQyScjlgxService;

    @Resource
    private ISpcyQyWlmlService spcyQyWlmlService;

    @Resource
    private ISpcyQyWlgyssjgxService spcyQyWlgyssjgxService;

    @Resource
    private ISpcyQyWlkcService spcyQyWlkcService;

    @Resource
    private ISpcyQyWlkcjlService spcyQyWlkcjlService;

    @Resource
    private ISpcyQyJyxxService spcyQyJyxxService;

    @Resource
    private ISpcyQyJcxmService spcyQyJcxmService;

    @Resource
    private ISpcyQyGjzbService spcyQyGjzbService;

    @Resource
    @Lazy
    private ISpcyQyRygwbgjlService spcyQyRygwbgjlService;

    @Resource
    @Lazy
    private ISpcyQyQywtxxService spcyQyQywtxxService;

    @Resource
    @Lazy
    private ISpcyQySbxxService spcyQySbxxService;

    @Resource
    private LocalFileUploadUtils localFileUploadUtils;

    @Resource
    private BusinessConstant businessConstant;

    @Resource
    private SpcyMinioUtils spcyMinioUtils;

    @Resource
    private ISpcyQyScgyService spcyQyScgyService;

    @Resource
    private ISpcyQyCzService spcyQyCzService;

    @Resource
    private ISpcyQyYftrService spcyQyYftrService;

    @Resource
    private ISpcyQyYpsczkService spcyQyYpsczkService;

    @Resource
    private ISpcyQyYpwtscService spcyQyYpwtscService;

    /**
     * 给企业新增账号
     * @param qyid 企业id
     */
    @Async(value = "asyncSimpleTask")
    public Result addUserQy(String qyid){
        return addUserQy(qyid, null);
    }
    public Result addUserQy(String qyid, SpcyQyJbxx qy){

        // 获取企业相关信息
        if (qy == null) {
            if (StringUtils.isBlank(qyid)){
                return Result.error("企业参数为空！");
            }

            qy = spcyQyJbxxService.selectQyById(qyid);
            if (qy == null) {
                return Result.error("当前企业不存在，请刷新重试");
            }
        }

        /** 验证账号是否存在 */
        List<String> isExistsQyUser = ycSysUserMapper.findUserIdByFqyid(qy.getId());
        if (CollectionUtils.isNotEmpty(isExistsQyUser)){
            return Result.error("该企业已经绑定账号！");
        }

        if (StringUtils.isBlank(qy.getFqymc())){
            return Result.error("当前企业名称为空, 设置账号失败，请完善相关信息");
        }

        if (StringUtils.isBlank(qy.getFtyshxydm())){
            return Result.error("当前企业["+qy.getFqymc()+"]社会信用代码为空，设置账号失败，请完善相关信息");
        }

        // 账号：统一社会信用代码
        String username = StringPatternUtils.trimString(qy.getFtyshxydm());

        // 名称：企业名称
        String realname = StringPatternUtils.trimString(qy.getFqymc());

        /** 验证账号是否存在 */
        List<String> isExistsUser = ycSysUserMapper.findUserIdByUserName(username+"_"+realname);
        if (CollectionUtils.isNotEmpty(isExistsUser)){
            return Result.error("当前企业名称【"+realname+"】已经存在【账号】为["+username+"]，无法再次设置账号。");
        }

        // 新增用户
        sysUserService.addQyAccountUser(GetUuIdUtils.ReplaceUuId(), username, realname, qy);

        return Result.ok("设置成功");
    }

    /**
     * 同步-行政审批-企业数据
     * @param tyshxydm 统一社会信用代码
     */
    public Result syncXzxkXdrxx(String tyshxydm){
        // 行政审批 - 企业信息
        List<XzspXzxdrJbxxVo> qyList = xzXkMapper.quertXzxdrJbxx(tyshxydm, null);
        if (CollectionUtils.isEmpty(qyList)){
            return Result.error("同步失败，社会信用代码【"+tyshxydm+"】不存在库中，无法同步。");
        }
        if (CollectionUtils.isNotEmpty(qyList)){
//            JSONObject xdrxx = MapUtils.mapToObject(qyList.get(0));
            XzspXzxdrJbxxVo xdrxx = qyList.get(0);
            // 企业id
            String qyid = xdrxx.getId();

            // 行政审批 - 企业人员信息
            List<Map<String, Object>> ryxxList = xzXkMapper.queryXzxdrRyxx(qyid);
            JSONArray ryxxArray = MapUtils.listMapToJson(ryxxList);

            SpcyQyJbxx qyJbxx = new SpcyQyJbxx();
            qyJbxx.setId(qyid);
            qyJbxx.setFtyshxydm(xdrxx.getTyshxydm()); // 统一社会信用代码
            qyJbxx.setFqymc(xdrxx.getXdrmc()); // 企业名称
            qyJbxx.setFqylxr(xdrxx.getLxr());   // 企业联系人
            qyJbxx.setFqylxrdh(xdrxx.getLxrsj()); // 企业联系人电话
            qyJbxx.setFqylxryx(xdrxx.getDzyx()); // 企业联系人邮箱
            qyJbxx.setFqyzszcdz(xdrxx.getZcdz()); // 企业住所/注册地址

            // 所在地区
            String szdq = "";
            if (StringUtils.isNotBlank(xdrxx.getSzds())){
                szdq += xdrxx.getSzds();
            }
            if (StringUtils.isNotBlank(xdrxx.getSzqx())){
                szdq += xdrxx.getSzqx();
            }
            if (StringUtils.isNotBlank(xdrxx.getSzxz())){
                szdq += xdrxx.getSzxz();
            }
            qyJbxx.setFszdq(szdq);  // 所在地区

            qyJbxx.setFxxdz(xdrxx.getZcdz()); // 详细地址
            qyJbxx.setFxzjg(xdrxx.getZzjgdm()); // 行政机构

            qyJbxx.setFwfcs(0);
            boolean save = spcyQyJbxxService.save(qyJbxx);
            if (save){
                String log = "同步-行政审批-企业信息：";
                log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(qyJbxx));

                spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, qyid,SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);
            }else {
                return Result.error("同步失败，系统错误，请刷新重试并联系管理员。");
            }


            if (CollectionUtils.isNotEmpty(ryxxArray)) {
                SpcyQyQygjryxx qygjryxx = null;
                for (int i=0; i < ryxxArray.size(); i++) {
                    qygjryxx = new SpcyQyQygjryxx();
                    JSONObject jsonObject = ryxxArray.getJSONObject(i);
                    qygjryxx.setFqyid(qyid); // 企业id
                    qygjryxx.setId(jsonObject.getString("id"));
                    qygjryxx.setFrylx(jsonObject.getString("ryfl")); // 人员类型
                    qygjryxx.setFgjry(jsonObject.getString("xm")); // 关键人员(姓名)
                    qygjryxx.setFlxdh(jsonObject.getString("sj")); // 联系电话
                    qygjryxx.setFyx(jsonObject.getString("dzyx")); // 邮箱
                    qygjryxx.setFsfzh(jsonObject.getString("zjhm")); // 身份证号
                    qygjryxx.setFxl(jsonObject.getString("xl")); // 学历
                    qygjryxx.setFzc(jsonObject.getString("zw")); // 职务、职称
                    qygjryxx.setFgzjl(jsonObject.getString("gzjl")); // 工作经历
                    qygjryxx.setFzjh(jsonObject.getString("lxdh")); // 座机号
                    qygjryxx.setFbz(jsonObject.getString("bz")); // 备注

                    boolean save1 = spcyQyQygjryxxService.save(qygjryxx);
                    if (save1){
                        String log = "同步-行政审批-企业信息-关键人员：";
                        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(qygjryxx));

                        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, qyid,SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);
                    }
                }
            }
        }

        return Result.ok("同步成功");
    }

    /** 同步-行政审批-企业数据-并且更新 */
    public Result syncUpdateXzxkXdrxx(String tyshxydm){
        if (StringUtils.isBlank(tyshxydm)){
            tyshxydm = null;
        }

        List<XzspXzxdrJbxxVo> qyList = xzXkMapper.quertXzxdrJbxx(tyshxydm, null);
        if (CollectionUtils.isEmpty(qyList)){
            return Result.error("同步失败，社会信用代码【"+tyshxydm+"】不存在库中，无法同步。");
        }

        for (XzspXzxdrJbxxVo xdrxx : qyList) {
            List<String> qyIdList = spcyQyJbxxService.selectIdByFtyshxydm(xdrxx.getTyshxydm());
            String qyid = "";
            if (CollectionUtil.isEmpty(qyIdList)){
                qyid = GetUuIdUtils.ReplaceUuId();

                SpcyQyJbxx qyJbxx = new SpcyQyJbxx();
                qyJbxx.setId(qyid);
                qyJbxx.setFtyshxydm(xdrxx.getTyshxydm()); // 统一社会信用代码
                qyJbxx.setFqymc(xdrxx.getXdrmc()); // 企业名称
                qyJbxx.setFqylxr(xdrxx.getLxr());   // 企业联系人
                qyJbxx.setFqylxrdh(xdrxx.getLxrsj()); // 企业联系人电话
                qyJbxx.setFqylxryx(xdrxx.getDzyx()); // 企业联系人邮箱
                qyJbxx.setFqyzszcdz(xdrxx.getZcdz()); // 企业住所/注册地址

                // 所在地区
                String szdq = "";
                if (StringUtils.isNotBlank(xdrxx.getSzds())){
                    szdq += xdrxx.getSzds();
                }
                if (StringUtils.isNotBlank(xdrxx.getSzqx())){
                    szdq += xdrxx.getSzqx();
                }
                if (StringUtils.isNotBlank(xdrxx.getSzxz())){
                    szdq += xdrxx.getSzxz();
                }
                qyJbxx.setFszdq(szdq);  // 所在地区

                qyJbxx.setFxxdz(xdrxx.getZcdz()); // 详细地址
                qyJbxx.setFxzjg(xdrxx.getZzjgdm()); // 行政机构
                qyJbxx.setFxkfw(xdrxx.getDjywfw()); // 生产范围
                qyJbxx.setFzch(xdrxx.getZch());

                qyJbxx.setFwfcs(0);
                spcyQyJbxxService.save(qyJbxx);

            }
            else {
                qyid = qyIdList.get(0);

                SpcyQyJbxx qyJbxx = spcyQyJbxxService.getById(qyid);
//                qyJbxx.setFtyshxydm(xdrxx.getTyshxydm()); // 统一社会信用代码
                qyJbxx.setFqymc(xdrxx.getXdrmc()); // 企业名称
                qyJbxx.setFqylxr(xdrxx.getLxr());   // 企业联系人
                qyJbxx.setFqylxrdh(xdrxx.getLxrsj()); // 企业联系人电话
                qyJbxx.setFqylxryx(xdrxx.getDzyx()); // 企业联系人邮箱
                qyJbxx.setFqyzszcdz(xdrxx.getZcdz()); // 企业住所/注册地址

                // 所在地区
                String szdq = "";
                if (StringUtils.isNotBlank(xdrxx.getSzds())){
                    szdq += xdrxx.getSzds();
                }
                if (StringUtils.isNotBlank(xdrxx.getSzqx())){
                    szdq += xdrxx.getSzqx();
                }
                if (StringUtils.isNotBlank(xdrxx.getSzxz())){
                    szdq += xdrxx.getSzxz();
                }
                qyJbxx.setFszdq(szdq);  // 所在地区

                qyJbxx.setFxxdz(xdrxx.getZcdz()); // 详细地址
                qyJbxx.setFxzjg(xdrxx.getZzjgdm()); // 行政机构
                qyJbxx.setFxkfw(xdrxx.getDjywfw()); // 生产范围
                qyJbxx.setFzch(xdrxx.getZch());

                spcyQyJbxxService.updateById(qyJbxx);
            }

            spcyQyQygjryxxService.remove(new LambdaQueryWrapper<SpcyQyQygjryxx>()
                    .eq(SpcyQyQygjryxx::getFqyid, qyid));

            List<XzspXzxdrXdrryVo> xdrryList = xzXkMapper.selectXzxdrRyxxByJbxxId(xdrxx.getId(), null, null);
            List<SpcyQyQygjryxx> ryxxList = new ArrayList<>(xdrryList.size());
            SpcyQyQygjryxx qygjryxx = null;
            for (XzspXzxdrXdrryVo xdrryVo : xdrryList){
                qygjryxx = new SpcyQyQygjryxx();

                qygjryxx.setFqyid(qyid); // 企业id
                qygjryxx.setId(xdrryVo.getId());
                qygjryxx.setFrylx(xdrryVo.getRyfl()); // 人员类型
                qygjryxx.setFgjry(xdrryVo.getXm()); // 关键人员(姓名)
                qygjryxx.setFlxdh(xdrryVo.getSj()); // 联系电话
                qygjryxx.setFyx(xdrryVo.getDzyx()); // 邮箱
                qygjryxx.setFsfzh(xdrryVo.getZjhm()); // 身份证号
                qygjryxx.setFxl(xdrryVo.getXl()); // 学历
                qygjryxx.setFzc(xdrryVo.getZw()); // 职务、职称
                qygjryxx.setFgzjl(xdrryVo.getGzjl()); // 工作经历
                qygjryxx.setFzjh(xdrryVo.getLxdh()); // 座机号
                qygjryxx.setFbz(xdrryVo.getBz()); // 备注
                qygjryxx.setFbm(xdrryVo.getBm()); // 部门
                qygjryxx.setFcsnx(xdrryVo.getCsnx());
                qygjryxx.setFzw(xdrryVo.getZw());

                ryxxList.add(qygjryxx);
            }

            spcyQyQygjryxxService.saveBatch(ryxxList);

        }


        return Result.ok();
    }

    /**
     * 同步政务服务-企业信息
     */
    public SpcyQyJbxx syncZwfwXdrxx(String qylx, int maxCount) {

        SpcyQyJbxx returnQy = null;

        // 行政审批 - 企业信息
        List<XzspXzxdrJbxxVo> qyList = xzXkMapper.quertXzxdrJbxx(null, qylx);
        if (CollectionUtils.isEmpty(qyList)) {
            throw new BusinessException("同步失败，不存在库中，无法同步。");
        }
        int count = 1;
        for (XzspXzxdrJbxxVo xdrxx : qyList) {
            if (count == maxCount){
                return returnQy;
            }
            count++;
//            JSONObject xdrxx = MapUtils.mapToObject(map);

            // 企业id
            String qyid = xdrxx.getId();
            SpcyQyJbxx qy = spcyQyJbxxService.getById(qyid);
            returnQy = qy;
            if (qy != null){
                continue;
            }

            // 行政审批 - 企业人员信息
            List<Map<String, Object>> ryxxList = xzXkMapper.queryXzxdrRyxx(qyid);
            JSONArray ryxxArray = MapUtils.listMapToJson(ryxxList);

            SpcyQyJbxx qyJbxx = new SpcyQyJbxx();
            qyJbxx.setId(qyid);
            qyJbxx.setFtyshxydm(xdrxx.getTyshxydm()); // 统一社会信用代码
            qyJbxx.setFqymc(xdrxx.getXdrmc()); // 企业名称
            qyJbxx.setFqylxr(xdrxx.getLxr());   // 企业联系人
            qyJbxx.setFqylxrdh(xdrxx.getLxrsj()); // 企业联系人电话
            qyJbxx.setFqylxryx(xdrxx.getDzyx()); // 企业联系人邮箱
            qyJbxx.setFqyzszcdz(xdrxx.getZcdz()); // 企业住所/注册地址

            // 所在地区
            String szdq = "";
            if (StringUtils.isNotBlank(xdrxx.getSzds())) {
                szdq += xdrxx.getSzds();
            }
            if (StringUtils.isNotBlank(xdrxx.getSzqx())) {
                szdq += xdrxx.getSzqx();
            }
            if (StringUtils.isNotBlank(xdrxx.getSzxz())) {
                szdq += xdrxx.getSzxz();
            }
            qyJbxx.setFszdq(szdq);  // 所在地区

            qyJbxx.setFxxdz(xdrxx.getZcdz()); // 详细地址
            qyJbxx.setFxzjg(xdrxx.getZzjgdm()); // 行政机构
            qyJbxx.setFcz(xdrxx.getCz()); // 传真

            qyJbxx.setFqyfddbrfzr(""); // 企业法定代表人/负责人
            qyJbxx.setFqyxkzh(xdrxx.getZch()); // 企业许可证号

            qyJbxx.setFwfcs(0);

            if (StringUtils.isBlank(qylx)) {
                qyJbxx.setFqylx("药品");
            } else if (qylx.equals("药品")) {
                qyJbxx.setFqylx("药品");
            } else if (qylx.equals("化妆品")) {
                qyJbxx.setFqylx("化妆品");
            } else if (qylx.equals("器械")) {
                qyJbxx.setFqylx("医疗器械");
            }else if (qylx.equals("啄木鸟")) {
                qyJbxx.setFqylx("医疗器械");
            }else if (qylx.equals("优利")) {
                qyJbxx.setFqylx("医疗器械");
            }else if (qylx.equals("信业")) {
                qyJbxx.setFqylx("医疗器械");
            }else if (qylx.equals("桂林南药")) {
                qyJbxx.setFqylx("药品");
            }else if (qylx.equals("广西维威")) {
                qyJbxx.setFqylx("药品");
            }else if (qylx.equals("葛洪堂")) {
                qyJbxx.setFqylx("药品");
            }else if (qylx.equals("广西名欧药业")) {
                qyJbxx.setFqylx("化妆品");
            }else if (qylx.equals("桂林杏润")) {
                qyJbxx.setFqylx("化妆品");
            }else if (qylx.equals("广西庆翠")) {
                qyJbxx.setFqylx("化妆品");
            }


            boolean save = spcyQyJbxxService.save(qyJbxx);
            if (!save) {
                continue;
            }

            if (CollectionUtils.isNotEmpty(ryxxArray)) {
                SpcyQyQygjryxx qygjryxx = null;
                for (int i = 0; i < ryxxArray.size(); i++) {
                    qygjryxx = new SpcyQyQygjryxx();
                    JSONObject jsonObject = ryxxArray.getJSONObject(i);
                    qygjryxx.setFqyid(qyid); // 企业id
                    qygjryxx.setId(jsonObject.getString("id"));
                    qygjryxx.setFrylx(jsonObject.getString("ryfl")); // 人员类型
                    qygjryxx.setFgjry(jsonObject.getString("xm")); // 关键人员(姓名)
                    qygjryxx.setFlxdh(jsonObject.getString("sj")); // 联系电话
                    qygjryxx.setFyx(jsonObject.getString("dzyx")); // 邮箱
                    qygjryxx.setFsfzh(jsonObject.getString("zjhm")); // 身份证号
                    qygjryxx.setFxl(jsonObject.getString("xl")); // 学历
                    qygjryxx.setFzc(jsonObject.getString("zw")); // 职务、职称
                    qygjryxx.setFgzjl(jsonObject.getString("gzjl")); // 工作经历
                    qygjryxx.setFzjh(jsonObject.getString("lxdh")); // 座机号
                    qygjryxx.setFbz(jsonObject.getString("bz")); // 备注

                    boolean save1 = spcyQyQygjryxxService.save(qygjryxx);
                    if (!save1) {
                        continue;
                    }
                }
            }
        }

        return returnQy;
    }

    /**
     * 同步政务服务-企业关键人员信息
     */
    public Result syncZwfwGjryxx(String tyshxydm){
        if (StringUtils.isBlank(tyshxydm)){
            return Result.error("参数为空！");
        }
        List<XzspXzxdrJbxxVo> qyList = xzXkMapper.quertXzxdrJbxx(tyshxydm, null);
        if (CollectionUtil.isEmpty(qyList)){
            return Result.error("没有相对应企业！");
        }
        List<SpcyQyJbxx> list = spcyQyJbxxService.list(new LambdaQueryWrapper<SpcyQyJbxx>()
                .eq(SpcyQyJbxx::getFtyshxydm, tyshxydm));
        if (list.size() == 1){

            String qyid = qyList.get(0).getId();
            String org_qyid = list.get(0).getId();

            // 行政审批 - 企业人员信息
            List<Map<String, Object>> ryxxList = xzXkMapper.queryXzxdrRyxx(qyid);
            JSONArray ryxxArray = MapUtils.listMapToJson(ryxxList);

            if (CollectionUtils.isNotEmpty(ryxxArray)) {
                SpcyQyQygjryxx qygjryxx = null;
                for (int i = 0; i < ryxxArray.size(); i++) {
                    qygjryxx = new SpcyQyQygjryxx();
                    JSONObject jsonObject = ryxxArray.getJSONObject(i);
                    qygjryxx.setFqyid(org_qyid); // 企业id
                    qygjryxx.setId(jsonObject.getString("id"));
                    qygjryxx.setFrylx(jsonObject.getString("ryfl")); // 人员类型
                    qygjryxx.setFgjry(jsonObject.getString("xm")); // 关键人员(姓名)
                    qygjryxx.setFlxdh(jsonObject.getString("sj")); // 联系电话
                    qygjryxx.setFyx(jsonObject.getString("dzyx")); // 邮箱
                    qygjryxx.setFsfzh(jsonObject.getString("zjhm")); // 身份证号
                    qygjryxx.setFxl(jsonObject.getString("xl")); // 学历
                    qygjryxx.setFzc(jsonObject.getString("zw")); // 职务、职称
                    qygjryxx.setFgzjl(jsonObject.getString("gzjl")); // 工作经历
                    qygjryxx.setFzjh(jsonObject.getString("lxdh")); // 座机号
                    qygjryxx.setFbz(jsonObject.getString("bz")); // 备注

                    try {
                        boolean save1 = spcyQyQygjryxxService.save(qygjryxx);
                        if (!save1) {
                            continue;
                        }
                    }catch (Exception e){
                        continue;
                    }
                }
            }
        }

        return Result.ok();
    }

    /**
     * 查询政务服务-企业关键人员信息库
     */
    public List<XzspXzxdrXdrryVo> selectXzxdrIdByTyshxydm(String tyshxydm){

        List<XzspXzxdrXdrryVo> xdrryList = null;
        String xzxdrid = "";
        try {
            xzxdrid = xzXkMapper.selectXzxdrIdByTyshxydm(tyshxydm);
        }catch (Exception e){
            log.error("查询政务服务-企业关键人员信息库-根据社会信用代码: {}; 查询相对人id错误：{}", tyshxydm, e.getMessage());
        }
        if (StringUtils.isNotBlank(xzxdrid)) {
            String fzrlxs = "01,02,03,04,06,11,18,19";
            xdrryList = xzXkMapper.selectXzxdrRyxxByJbxxId(xzxdrid, fzrlxs, null);
        }

        return xdrryList;
    }

    /**
     * 删除企业相关信息
     */
    public Result deleteQyInfoXX(String fqyid){
        spcyQyWfwjjlService.remove(new LambdaQueryWrapper<SpcyQyWfwjjl>().eq(SpcyQyWfwjjl::getFqyid, fqyid));
        spcyQyQygjryxxService.remove(new LambdaQueryWrapper<SpcyQyQygjryxx>().eq(SpcyQyQygjryxx::getFqyid, fqyid));
        spcyQyPzjbxxService.remove(new LambdaQueryWrapper<SpcyQyPzjbxx>().eq(SpcyQyPzjbxx::getFqyid, fqyid));
//        spcyQyCppcxxService.remove(new LambdaQueryWrapper<SpcyQyCppcxx>().eq(SpcyQyCppcxx::getFqyid, fqyid));

        // 产品偏差信息
        List<SpcyQyCppcxx> cppcxxList = spcyQyCppcxxService.list(new LambdaQueryWrapper<SpcyQyCppcxx>().eq(SpcyQyCppcxx::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(cppcxxList)){
            for (SpcyQyCppcxx cppcxx : cppcxxList){
                spcyQyCppcxxService.removeById(cppcxx.getId());
                this.deleteCppcxx(cppcxx.getId());
            }
        }

        // 工艺验证
        List<SpcyQyGyyz> gyyzlist = spcyQyGyyzService.list(new LambdaQueryWrapper<SpcyQyGyyz>().eq(SpcyQyGyyz::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(gyyzlist)){
            for (SpcyQyGyyz gyyz : gyyzlist){
                spcyQyGyyzService.removeById(gyyz.getId());
                this.deleteGyyz(gyyz.getId());
            }
        }

        // 检查信息
        List<SpcyQyJcxx> jcxxlist = spcyQyJcxxService.list(new LambdaQueryWrapper<SpcyQyJcxx>().eq(SpcyQyJcxx::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(jcxxlist)){
            for (SpcyQyJcxx jcxx : jcxxlist){
                spcyQyJcxxService.removeById(jcxx.getId());
                this.deleteJcxx(jcxx.getId());
            }
        }

        // 清洁验证
        List<SpcyQyQjyz> qjyzlist = spcyQyQjyzService.list(new LambdaQueryWrapper<SpcyQyQjyz>().eq(SpcyQyQjyz::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(qjyzlist)){
            for (SpcyQyQjyz jcxx : qjyzlist){
                spcyQyQjyzService.removeById(jcxx.getId());
                this.deleteQjyz(jcxx.getId());
            }
        }

        // 设备确认
        List<SpcyQySbqrxx> sbqrxxlist = spcyQySbqrxxService.list(new LambdaQueryWrapper<SpcyQySbqrxx>().eq(SpcyQySbqrxx::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(sbqrxxlist)){
            for (SpcyQySbqrxx jcxx : sbqrxxlist){
                spcyQySbqrxxService.removeById(jcxx.getId());
                this.deleteSbqrxx(jcxx.getId());
            }
        }

        // 供应商
        List<SpcyQyYlgyssj> ylgyssjlist = spcyQyYlgyssjService.list(new LambdaQueryWrapper<SpcyQyYlgyssj>().eq(SpcyQyYlgyssj::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(ylgyssjlist)){
            for (SpcyQyYlgyssj jcxx : ylgyssjlist){
                spcyQyYlgyssjService.removeById(jcxx.getId());
                this.deleteYlgyssj(jcxx.getId());
            }
        }

        // 变更控制
        List<SpcyQyBgkz> bgkzList = spcyQyBgkzService.list(new LambdaQueryWrapper<SpcyQyBgkz>().eq(SpcyQyBgkz::getFqyid, fqyid));
        if (CollectionUtils.isNotEmpty(bgkzList)){
            for (SpcyQyBgkz bgkz : bgkzList){
                spcyQyBgkzService.removeById(bgkz.getId());
                this.deleteBgkz(bgkz.getId());
            }
        }

        // 删除企业相关文件
        this.deleteInfoFileByFpid(fqyid);

        return Result.ok("删除成功");
    }

    /**
     * 获取当前登录用户绑定的企业id
     * @return
     */
    public String getCurrentQy(){
        String qyid = sysUserService.selectFqyidById(GetCurrentUserUtils.getCurrentUserId());

        return StringUtils.isNotBlank(qyid) ? qyid : "0";
    }

    /** 获取企业id根据社会信用代码 */
    public String getQyIdByTyshxydm(String tyshxydm){
        List<String> list = spcyQyJbxxService.selectIdByFtyshxydm(tyshxydm);
        if (CollectionUtil.isNotEmpty(list)){
            return  list.get(0);
        }

        return "0";
    }

    /** 根据企业id-查询统一社会信用代码  */
    public String getTyshxydmById(String fqyid){
        return Optional.ofNullable(spcyQyJbxxService.selectQyFtyshxydmById(fqyid)).orElse("");
    }

    /************************************[ 企业-企业基本信息 ]**************************************************************************/

    /**
     * 获取企业详情
     */
    public Map queryQyJbxxById(String qyid,boolean onlyCurrentUser){
        Map resultMap = new HashMap();

        if (StringUtils.isBlank(qyid)){
            if (onlyCurrentUser){
                qyid = this.getCurrentQy();
            }
        }

        // 获取当前企业基本信息 1
        SpcyQyJbxx qyxx = spcyQyJbxxService.getById(qyid);
        resultMap.put("qyxx", qyxx);

        return resultMap;
    }

    /**
     * 修改企业信息
     * @param buffer
     */
    public HttpResult editQyxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("企业基本信息id不能为空");
        }

        String qyId = buffer.get("id");
        SpcyQyJbxx updateBean = spcyQyJbxxService.getById(qyId);
        if (updateBean == null){
            return HttpResult.error("没有相匹配的企业信息！");
        }

        SpcyQyJbxx oldBean = updateBean;

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);

        if (StringUtils.isNotBlank(updateBean.getFtyshxydm())){
            if (StringUtils.isBlank(oldBean.getFtyshxydm())){
                List<String> existsList = spcyQyJbxxService.selectFtyshxydmByFtyshxydm(updateBean.getFtyshxydm());
                if (CollectionUtil.isNotEmpty(existsList)){
                    return HttpResult.error("["+updateBean.getFtyshxydm()+"]该社会信用代码已经存在！");
                }
            }else if (!oldBean.getFtyshxydm().equals(updateBean.getFtyshxydm())){
                List<String> existsList = spcyQyJbxxService.selectFtyshxydmByFtyshxydm(updateBean.getFtyshxydm());
                if (CollectionUtil.isNotEmpty(existsList)) {
                    return HttpResult.error("[" + updateBean.getFtyshxydm() + "]该社会信用代码已经存在！");
                }
            }
        }

        boolean flag = spcyQyJbxxService.updateById(updateBean);
        if (flag) {
            String operContent = "基本信息修改：";
            operContent += LogUtils.BeanModifyMsg(updateBean, ObjectToMapUtils.objectToMap(oldBean));

            spcyLogService.addLogs(LogConstant.LOGS_QY_JBXX, operContent, qyId, "修改企业信息", SpcyConstant.LOGS_SYS_TYPE_XG);
        }else {
            return HttpResult.error("保存失败，请刷新重试,并联系管理员");
        }

        return HttpResult.ok("保存成功");
    }

    /************************************[ 企业-品种基本信息 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryPzjbxxPageList(SpcyQyPzjbxx spcyQyPzjbxx, Integer pageNo, Integer pageSize) {
        Page<SpcyQyPzjbxx> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyPzjbxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyPzjbxx.getFqyid()),SpcyQyPzjbxx::getFqyid,spcyQyPzjbxx.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyPzjbxx.getFpzwh()),SpcyQyPzjbxx::getFpzwh,spcyQyPzjbxx.getFpzwh());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyPzjbxx.getFtymc()),SpcyQyPzjbxx::getFtymc,spcyQyPzjbxx.getFtymc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyPzjbxx.getFcplb()),SpcyQyPzjbxx::getFcplb,spcyQyPzjbxx.getFcplb());
        queryWrapper.orderByAsc(SpcyQyPzjbxx::getCreateTime);
        IPage<SpcyQyPzjbxx> pageList = spcyQyPzjbxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /** 导出品种信息 */
    public List<SpcyQyPzjbxx> selectPzxxList(String fqyid){
        return spcyQyPzjbxxService.list(new LambdaQueryWrapper<SpcyQyPzjbxx>()
                .eq(SpcyQyPzjbxx::getFqyid, fqyid)
                .orderByAsc(SpcyQyPzjbxx::getCreateTime));
    }

    /** 导出企业-品种信息 */
    @Transactional(rollbackFor = Exception.class)
    public boolean importQyPzxxByFqyid(String tyshxydm, String fqyid, List<Map<String, Object>> dataMapList){
        if (StringUtils.isBlank(fqyid)){
            fqyid = "0";

            if (StringUtils.isNotBlank(tyshxydm)) {
                List<String> list = spcyQyJbxxService.selectIdByFtyshxydm(tyshxydm);
                if (CollectionUtil.isNotEmpty(list)){
                    fqyid = list.get(0);
                }
            }
        }

        List<SpcyQyPzjbxx> dataList = new ArrayList<>(dataMapList.size());
        for (Map map : dataMapList) {
            SpcyQyPzjbxx bean = new SpcyQyPzjbxx();
            BeanUtil.copyProperties(map, bean);
            bean.setFqyid(fqyid);
            bean.setId(GetUuIdUtils.NotReplaceUuId());

            dataList.add(bean);
        }

        boolean flag = spcyQyPzjbxxService.saveBatch(dataList);
        if (!flag){
            return false;
        }

        return true;
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addPzjbxx(SpcyQyPzjbxx pzjbxx, boolean onlyCurrentUser){
        pzjbxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            pzjbxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(pzjbxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyPzjbxxService.save(pzjbxx);

        String log = "添加-企业-品种基本信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(pzjbxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,pzjbxx.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(pzjbxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updatePzjbxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyPzjbxx Update = spcyQyPzjbxxService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyPzjbxxService.updateById(Update);

        String operContent = "企业-品种基本信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deletePzjbxx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyPzjbxx> sqsxWjmlList = spcyQyPzjbxxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyPzjbxx wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyPzjbxxService.removeById(id);

            operContent = "删除-企业品种基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryPzjbxxById(String id) {
        SpcyQyPzjbxx jbxx = spcyQyPzjbxxService.getById(id);
        return HttpResult.ok(jbxx);
    }

    /************************************[ 企业-物料目录 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryWlmlPageList(SpcyQyWlml wlml, Integer pageNo, Integer pageSize) {
        Page<SpcyQyWlml> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyWlml> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(wlml.getFqyid()),SpcyQyWlml::getFqyid,wlml.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(wlml.getFgg()),SpcyQyWlml::getFgg,wlml.getFgg());
        queryWrapper.like(StringUtils.isNotEmpty(wlml.getFwlbh()),SpcyQyWlml::getFwlbh,wlml.getFwlbh());
        queryWrapper.like(StringUtils.isNotEmpty(wlml.getFwlmc()),SpcyQyWlml::getFwlmc,wlml.getFwlmc());
        queryWrapper.orderByDesc(SpcyQyWlml::getCreateTime);
        IPage<SpcyQyWlml> pageList = spcyQyWlmlService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 获取所有物料列表
     * @return
     */
    public List<SpcyQyWlml> queryAllWlmlList(SpcyQyWlml wlml){
        if (StringUtils.isBlank(wlml.getFqyid())){
            throw new BusinessException("企业参数为空！");
        }
        LambdaQueryWrapper<SpcyQyWlml> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(wlml.getFqyid()),SpcyQyWlml::getFqyid,wlml.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(wlml.getFgg()),SpcyQyWlml::getFgg,wlml.getFgg());
        queryWrapper.like(StringUtils.isNotEmpty(wlml.getFwlbh()),SpcyQyWlml::getFwlbh,wlml.getFwlbh());
        queryWrapper.like(StringUtils.isNotEmpty(wlml.getFwlmc()),SpcyQyWlml::getFwlmc,wlml.getFwlmc());
        queryWrapper.orderByDesc(SpcyQyWlml::getCreateTime);
        List<SpcyQyWlml> list = spcyQyWlmlService.list(queryWrapper);

//        List<WlkcParamBo> list = spcyQyWlmlMapper.findAllWlkcList(wlml);

        return list;
    }

    /**
     * 获取所有物料库存-分页列表
     * @param wlml
     * @param pageNo
     * @param pageSize
     * @return
     */
    public HttpResult queryAllWlKcList(WlkcParamBo wlml,Integer pageNo, Integer pageSize){
        if (StringUtils.isBlank(wlml.getFqyid())){
            throw new BusinessException("企业参数为空！");
        }
        Page<WlkcParamBo> page = new Page<>(pageNo, pageSize);
        Page<WlkcParamBo> list = spcyQyWlmlMapper.findAllWlkcList(page,wlml);

        return HttpResult.ok(list);
    }

    /**
     * 物料统计
     */
    public HttpResult QueryWlStatList(WlStatListDto query,Integer pageNo, Integer pageSize){
        if (StringUtils.isBlank(query.getFqyid())){
            throw new BusinessException("企业参数为空！");
        }
        Page<WlStatListDto> page = new Page<>(pageNo, pageSize);
        Page<WlStatListDto> pageList = spcyQyWlmlMapper.findWlStatList(page, query);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addWlml(SpcyQyWlml bean, boolean onlyCurrentUser){
        bean.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            bean.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(bean.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyWlmlService.save(bean);

        String log = "添加-企业-物料目录信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,bean.getFqyid(), "添加企业物料目录信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(bean);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateWlml(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyWlml Update = spcyQyWlmlService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyWlmlService.updateById(Update);

        String operContent = "企业-物料目录基本信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,Update.getFqyid(),"企业-物料目录基本信息-修改",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteWlml(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyWlml> sqsxWjmlList = spcyQyWlmlService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyWlml wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyWlmlService.removeById(id);

            operContent = "删除-企业物料目录基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjml.getFqyid(),"删除企业物料目录基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }


    /************************************[ 企业-物料目录库存 ]**************************************************************************/

    /** 新增物料与供应商审计关系
     * @param fwlmlid 物料目录id
     * @param fwlsjid 物料供应商审计id
     * */
    public void addWlgyssjGx(String fwlmlid, String fwlsjid){
        if (StringUtils.isBlank(fwlmlid)){
            throw new BusinessException("物料参数为空！");
        }
        if (StringUtils.isBlank(fwlsjid)){
            throw new BusinessException("供应商参数为空！");
        }

        SpcyQyYlgyssj gyssj = spcyQyYlgyssjService.getById(fwlsjid);
        if (gyssj == null){
            throw new BusinessException("当前供应商审计不存在！");
        }

        List<String> wlIdList = StringPatternUtils.getListByIds(fwlmlid);
        for (String wlid : wlIdList) {

            SpcyQyWlml wlml = spcyQyWlmlService.getById(wlid);
            if (wlml == null){
                continue;
            }

            List<SpcyQyWlgyssjgx> list = spcyQyWlgyssjgxService.list(new LambdaQueryWrapper<SpcyQyWlgyssjgx>()
                    .eq(SpcyQyWlgyssjgx::getFwlmlid, wlid)
                    .eq(SpcyQyWlgyssjgx::getFwlsjid, fwlsjid));
            if (CollectionUtil.isNotEmpty(list)) {
                continue;
            }

            spcyQyWlgyssjgxService.addWlgyssjGx(wlid, fwlsjid);

            String log = "新增物料与供应商审计关系：";
            log += "物料id：[" + fwlmlid + "]";
            log += "物料供应商审计id：[" + fwlsjid + "]";
            log += "物料编号：[" + wlml.getFwlbh() + "]";
            log += "物料名称：[" + wlml.getFwlmc() + "]";
            log += "经销商名称：[" + gyssj.getFjxsmc() + "]";
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, wlml.getFqyid(), "新增物料与供应商审计关系", SpcyConstant.LOGS_SYS_TYPE_XZ);
        }

    }

    /** 删除物料与供应商审计关系 */
    public void deleteWlgyssjGx(String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空！");
        }
        SpcyQyWlgyssjgx wlgys = spcyQyWlgyssjgxService.getById(id);
        if (wlgys == null){
            throw new BusinessException("当前物料审计数据不存在！");
        }
        spcyQyWlgyssjgxService.deleteWlgyssjGx(id);

        String log = "删除物料与供应商审计关系：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(wlgys));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, id, "删除物料与供应商审计关系",SpcyConstant.LOGS_SYS_TYPE_SC);
    }

    /**
     * 获取物料与供应商审计列表
     * */
    public List<WlGyssjParamBo> queryWlgyssjBySjIdList(String fwlsjid){
        List<WlGyssjParamBo> list = spcyQyWlmlMapper.findWlAndGyssjList(fwlsjid);

        return list;
    }

    /**
     * 获取对应物料目录的供应商审计
     * */
    public List<QyYlgyssjYjxxParamBo> queryGyssjByWlIdList(String fwlmlid){
        if (StringUtils.isBlank(fwlmlid)){
            throw new BusinessException("物料参数为空！");
        }

        QyYlgyssjYjxxParamBo paramBo = new QyYlgyssjYjxxParamBo();
        if (StringUtils.isNotBlank(paramBo.getSfgq())){
            if (paramBo.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX)){
                paramBo.setCqyx(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX);

            }else if (paramBo.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_WGQ)){
                paramBo.setWgq(DateUtil.today());

            }else if (paramBo.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ)){
                paramBo.setYgqsj(DateUtil.today());

            }else if (paramBo.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ)){
                // 提交几个月进行预警
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
                paramBo.setWgq(DateUtil.today());
                paramBo.setJjgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }else if (paramBo.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX)){
                // 几个月以上有效
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
                paramBo.setWgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }
        }

        paramBo.setNowDay(DateUtil.today());

        Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
        paramBo.setGqDay(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

        Date yxDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
        paramBo.setYxDay(DateConversionUtils.DateToStringYYYYMMDD(yxDate));

        List<QyYlgyssjYjxxParamBo> list = spcyQyWlmlMapper.findWlGyssjList(fwlmlid, paramBo);

        return list;
    }

    /**
     * 获取物料库存列表
     */
    public HttpResult queryWlkcPageList(WlkcParamBo query,Integer pageNo,Integer pageSize){
        Page<WlkcParamBo> page = new Page<>(pageNo,pageSize);

        Page<WlkcParamBo> wlkcList = spcyQyWlmlMapper.findWlkcListPage(page, query);
        return HttpResult.ok(wlkcList);
    }

    /**
     * 查看物料库存
     */
    public WlkcParamBo queryWlkcById(String kcid){
        WlkcParamBo kc = spcyQyWlmlMapper.findWlkcById(kcid);
        return kc;
    }

    /**
     * 查看库存操作记录
     */
    public List<SpcyQyWlkcjl> queryWlkcjl(String kcid){
        List<SpcyQyWlkcjl> list = spcyQyWlkcjlService.findKcjlByKcId(null, kcid);
        return list;
    }

    /**
     * 获取物料下的库存
     */
    private SpcyQyWlkc getWlkcByWlid(String fwlmlid){
        List<SpcyQyWlkc> list = spcyQyWlkcService.list(new LambdaQueryWrapper<SpcyQyWlkc>()
                .eq(SpcyQyWlkc::getFwlmlid, fwlmlid)
                .gt(SpcyQyWlkc::getFkcsl, 0)
                .orderByDesc(SpcyQyWlkc::getFkcsl)
                .orderByDesc(SpcyQyWlkc::getFrksj));
        if (CollectionUtil.isEmpty(list)){
            throw new BusinessException("当前物料没有剩余库存，请先进行补充！");
        }

        return list.get(0);
    }

    /**
     * 修改库存数量
     * @param isAdd true: 新增/false: 减少
     */
    private void modifyWlkcNumber(boolean isAdd, String kcid, SpcyQyWlkc wlkc, Integer num){
        if (wlkc == null) {
            wlkc = spcyQyWlkcService.getById(kcid);
        }
        if (wlkc == null){
            throw new BusinessException("没有想匹配的物料库存信息！");
        }
        Integer oldNum = wlkc.getFkcsl();
        if (isAdd){
            oldNum = oldNum + num;
        }else {
            if (oldNum < num){
                throw new BusinessException("当前物料库存不足！剩余库存["+oldNum+"]");
            }
            oldNum = oldNum - num;
        }
        wlkc.setFkcsl(oldNum);
        spcyQyWlkcService.updateById(wlkc);
    }

    /**
     * 新增物料库存
     * @param wlkc
     */
    public SpcyQyWlkc addWlkc(SpcyQyWlkc wlkc){
        wlkc.setId(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isBlank(wlkc.getFwlmlid())){
            throw new BusinessException("请选择物料目录！");
        }
        if (StringUtils.isBlank(wlkc.getFwlsjid())){
            throw new BusinessException("请选择物料供应商！");
        }

        SpcyQyWlml wlml = spcyQyWlmlService.getById(wlkc.getFwlmlid());
        if (wlml == null){
            throw new BusinessException("当前物料不存在！");
        }

        SpcyQyYlgyssj gyssj = spcyQyYlgyssjService.getById(wlkc.getFwlsjid());
        if (gyssj == null){
            throw new BusinessException("当前供应商审计不存在！");
        }

        if (wlkc.getFkcsl() == null){
            wlkc.setFkcsl(0);
        }
        if (StringUtils.isBlank(wlkc.getFyxq())){
            throw new BusinessException("请选择物料供应商！");
        }
        if (StringUtils.isBlank(wlkc.getFrkph())){
            throw new BusinessException("请选择物料供应商！");
        }
        wlkc.setFrksj(new Date());

        spcyQyWlkcService.save(wlkc);
        spcyQyWlkcjlService.addRckRecords(wlkc.getId(), SpcyCommonConstant.QY_RKJL_LX_RK, wlkc.getFkcsl(), "添加库存:"+wlml.getFwlbh()+"/"+wlml.getFwlmc());

        String log = "添加-企业-物料库存信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(wlkc));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, wlml.getFqyid(), "添加企业物料库存信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        return wlkc;
    }

    /**
     * 更新物料库存
     */
    public void updateWlkc(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            throw new BusinessException("参数为空！");
        }
        String wjmlId = buffer.get("id");
        SpcyQyWlkc Update = spcyQyWlkcService.getById(wjmlId);
        if (Update == null){
            throw new BusinessException("当前数据不存在！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);

        if (StringUtils.isBlank(Update.getFwlmlid())){
            throw new BusinessException("请选择物料目录！");
        }

        if (StringUtils.isBlank(Update.getFwlsjid())){
            throw new BusinessException("请选择物料供应商！");
        }

        SpcyQyWlml wlml = spcyQyWlmlService.getById(Update.getFwlmlid());
        if (wlml == null){
            throw new BusinessException("当前物料不存在！");
        }

        SpcyQyYlgyssj gyssj = spcyQyYlgyssjService.getById(Update.getFwlsjid());
        if (gyssj == null){
            throw new BusinessException("当前供应商审计不存在！");
        }

        if (Update.getFkcsl() == null){
            Update.setFkcsl(0);
        }

        spcyQyWlkcService.updateById(Update);
        spcyQyWlkcjlService.addRckRecords(Update.getId(), SpcyCommonConstant.QY_RKJL_LX_RK, Update.getFkcsl(), "修改库存:"+wlml.getFwlbh()+"/"+wlml.getFwlmc());

        String operContent = "企业-物料库存基本信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wlml.getFqyid(),"企业-物料库存基本信息-修改",SpcyConstant.LOGS_SYS_TYPE_XG);
    }

    /**
     * 删除物料库存
     */
    public void deleteWlkc(String ids){
        if (StringUtils.isEmpty(ids)){
            throw new BusinessException("参数为空！");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyWlkc> list = spcyQyWlkcService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            throw new BusinessException("当前数据不匹配！");
        }
        String operContent = "";
        for (SpcyQyWlkc wjml : list){
            String id = wjml.getId();
            spcyQyWlmlService.removeById(id);

            operContent = "删除-企业物料库存基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjml.getId(),"删除企业物料库存基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }
    }

    /************************************[ 企业-关键人员信息 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryQygjryxxPageList(SpcyQyQygjryxx spcyQyQygjryxx, Integer pageNo, Integer pageSize) {
        Page<SpcyQyQygjryxx> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyQygjryxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyQygjryxx.getFqyid()),SpcyQyQygjryxx::getFqyid,spcyQyQygjryxx.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyQygjryxx.getFgjry()),SpcyQyQygjryxx::getFgjry,spcyQyQygjryxx.getFgjry());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyQygjryxx.getFsfzh()),SpcyQyQygjryxx::getFsfzh,spcyQyQygjryxx.getFsfzh());

        queryWrapper.orderByDesc(SpcyQyQygjryxx::getCreateTime);
        IPage<SpcyQyQygjryxx> pageList = spcyQyQygjryxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 获取企业其他人员信息接口
     * */
    public List<SpcyQyQygjryxx> selectQyQtryxxByTyshxydm(String fqyid){

        LambdaQueryWrapper<SpcyQyQygjryxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(fqyid),SpcyQyQygjryxx::getFqyid,fqyid);
        queryWrapper.eq(SpcyQyQygjryxx::getFrylx, XzXkConstant.RYFL_QTRY);

        return spcyQyQygjryxxService.list(queryWrapper);
    }

    /** 导出企业其他人员信息 */
    @Transactional(rollbackFor = Exception.class)
    public boolean importQyQtryxxByTyshxydm(String tyshxydm, String fqyid, List<Map<String, Object>> dataMapList){
        if (StringUtils.isBlank(fqyid)){
            fqyid = "0";

            if (StringUtils.isNotBlank(tyshxydm)) {
                List<String> list = spcyQyJbxxService.selectIdByFtyshxydm(tyshxydm);
                if (CollectionUtil.isNotEmpty(list)){
                    fqyid = list.get(0);
                }
            }
        }

        List<SpcyQyQygjryxx> dataList = new ArrayList<>(dataMapList.size());
        for (Map map : dataMapList) {
            SpcyQyQygjryxx bean = new SpcyQyQygjryxx();
            BeanUtil.copyProperties(map, bean);
            bean.setFrylx(XzXkConstant.RYFL_QTRY);
            bean.setFqyid(fqyid);
            bean.setId(GetUuIdUtils.NotReplaceUuId());

            dataList.add(bean);
        }

        boolean flag = spcyQyQygjryxxService.saveBatch(dataList);
        if (!flag){
            return false;
        }

        return true;
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addQygjryxx(SpcyQyQygjryxx jbxx, boolean onlyCurrentUser){
        jbxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            jbxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(jbxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyQygjryxxService.save(jbxx);

        String log = "添加-企业-关键人员信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(jbxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,jbxx.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(jbxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateQygjryxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyQygjryxx Update = spcyQyQygjryxxService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyQygjryxxService.updateById(Update);

        String operContent = "企业-关键人员信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteQygjryxx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyQygjryxx> sqsxWjmlList = spcyQyQygjryxxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyQygjryxx wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyQygjryxxService.removeById(id);

            operContent = "删除-关键人员信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryQygjryxx(String id) {
        SpcyQyQygjryxx jbxx = spcyQyQygjryxxService.getById(id);
        return HttpResult.ok(jbxx);
    }

    /**
     * 查询企业人员-关键人员姓名
     */
    public QyGjryBo selectQyGjryXx(String id){

        String fzrlxs = XzXkConstant.RYFL_FDDBR_CODE;
        fzrlxs +=  "," + XzXkConstant.RYFL_QYFZR_CODE;
        fzrlxs +=  "," + XzXkConstant.RYFL_QYZLFZR_CODE;
        fzrlxs +=  "," + XzXkConstant.RYFL_SCFZR_CODE;
        fzrlxs +=  "," + XzXkConstant.RYFL_ZLSQR_CODE;
        List<XzspXzxdrXdrryVo> ryList = xzXkMapper.selectXzxdrRyjbxxByJbxxId(id, fzrlxs);

        QyGjryBo gjryBo = new QyGjryBo();
        for (XzspXzxdrXdrryVo ry : ryList){
            if (StringUtils.isBlank(ry.getFzrlx())){
                continue;
            }

            if ( ry.getFzrlx().equals(XzXkConstant.RYFL_FDDBR_CODE)){
                gjryBo.setFddbr(ry.getXm());
            }else if (ry.getFzrlx().equals(XzXkConstant.RYFL_QYFZR_CODE)){
                gjryBo.setQyfzr(ry.getXm());
            }else if ( ry.getFzrlx().equals(XzXkConstant.RYFL_QYZLFZR_CODE)){
                gjryBo.setQyzlglr(ry.getXm());
            }else if ( ry.getFzrlx().equals(XzXkConstant.RYFL_SCFZR_CODE)){
                gjryBo.setScfzr(ry.getXm());
            }else if ( ry.getFzrlx().equals(XzXkConstant.RYFL_ZLSQR_CODE)){
                gjryBo.setZlsqr(ry.getXm());
            }else if ( ry.getFzrlx().equals(XzXkConstant.RYFL_ZLGLBMFZR_CODE)){
                gjryBo.setZlglbmfzr(ry.getXm());
            }
        }

        return gjryBo;
    }

    /************************************[ 企业-人员岗位变更记录 ]**************************************************************************/

    public HttpResult<?> queryQyRyBgjlPageList(SpcyQyRygwbgjl query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyRygwbgjl> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyRygwbgjl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()),SpcyQyRygwbgjl::getFqyid,query.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(query.getFgjry()),SpcyQyRygwbgjl::getFgjry,query.getFgjry());
        queryWrapper.like(StringUtils.isNotEmpty(query.getFsfzh()),SpcyQyRygwbgjl::getFsfzh,query.getFsfzh());
        queryWrapper.like(StringUtils.isNotEmpty(query.getFrylx()),SpcyQyRygwbgjl::getFrylx,query.getFrylx());
        queryWrapper.like(StringUtils.isNotEmpty(query.getFbghgw()),SpcyQyRygwbgjl::getFbghgw,query.getFbghgw());

        queryWrapper.orderByDesc(SpcyQyRygwbgjl::getCreateTime);
        IPage<SpcyQyRygwbgjl> pageList = spcyQyRygwbgjlService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    // 添加人员岗位变更记录
    public void addRygwbgjl(String id, String fbghgw) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空！");
        }
        if (StringUtils.isBlank(fbghgw)){
            throw new BusinessException("岗位变更参数为空!");
        }
        SpcyQyQygjryxx ryxx = spcyQyQygjryxxService.getById(id);

        if (StringUtils.isNotBlank(ryxx.getFrylx()) && ryxx.getFrylx().equals(fbghgw)){
            throw new BusinessException("操作失败，变更岗位与原岗位相同！");
        }

        SpcyQyRygwbgjl bgjl = new SpcyQyRygwbgjl();
        BeanUtils.copyProperties(bgjl, ryxx);
        bgjl.setFbghgw(fbghgw);
        bgjl.setId(GetUuIdUtils.ReplaceUuId());
        bgjl.setCreateTime(new Date());
        spcyQyRygwbgjlService.save(bgjl);

        ryxx.setFrylx(fbghgw);
        spcyQyQygjryxxService.updateById(ryxx);

        String log = "添加-企业关键人员变更信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bgjl));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,bgjl.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

    }

    /************************************[ 企业-原料供应商审计 ]**************************************************************************/

    /**
     * 供应商信息分页查询
     */
    public HttpResult selectGysxxPageList(SpcyQyYlgyssj query, String gjz, PageVo pageVo){
        LambdaQueryWrapper<SpcyQyYlgyssj> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()), SpcyQyYlgyssj::getFqyid, query.getFqyid());
        queryWrapper.like(StringUtils.isNotBlank(query.getFjxsmc()), SpcyQyYlgyssj::getFjxsmc, query.getFjxsmc());

        if (StringUtils.isNotBlank(gjz)){
            queryWrapper.and(q->q.like(SpcyQyYlgyssj::getFwlbh, gjz)
                    .or()
                    .like(SpcyQyYlgyssj::getFwlmc, gjz)
                    .or()
                    .like(SpcyQyYlgyssj::getFjxsmc, gjz)
                    .or()
                    .like(SpcyQyYlgyssj::getFscsmc, gjz)
            );
        }

        queryWrapper.orderByAsc(SpcyQyYlgyssj::getCreateTime);
        return HttpResult.ok(spcyQyYlgyssjService.page(new Page<>(pageVo.getPageNo(), pageVo.getPageSize()), queryWrapper));
    }

    /** 导出供应商信息 */
    public List<SpcyQyYlgyssj> selectGysxxList(String fqyid){
        return spcyQyYlgyssjService.list(new LambdaQueryWrapper<SpcyQyYlgyssj>()
                .eq(SpcyQyYlgyssj::getFqyid, fqyid));
    }

    /** 导出企业-供应商信息 */
    @Transactional(rollbackFor = Exception.class)
    public boolean importQyGysxxByFqyid(String tyshxydm, String fqyid, List<Map<String, Object>> dataMapList){
        if (StringUtils.isBlank(fqyid)){
            fqyid = "0";

            if (StringUtils.isNotBlank(tyshxydm)) {
                List<String> list = spcyQyJbxxService.selectIdByFtyshxydm(tyshxydm);
                if (CollectionUtil.isNotEmpty(list)){
                    fqyid = list.get(0);
                }
            }
        }

        List<SpcyQyYlgyssj> dataList = new ArrayList<>(dataMapList.size());
        for (Map map : dataMapList) {
            SpcyQyYlgyssj bean = new SpcyQyYlgyssj();
            BeanUtil.copyProperties(map, bean);
            bean.setFqyid(fqyid);
            bean.setId(GetUuIdUtils.NotReplaceUuId());

            dataList.add(bean);
        }

        boolean flag = spcyQyYlgyssjService.saveBatch(dataList);
        if (!flag){
            return false;
        }

        return true;
    }
    /**
     * 分页查询
     */
    public HttpResult<?> queryYlgyssjPageList(QyYlgyssjYjxxParamBo spcyQyYlgyssj, Integer pageNo, Integer pageSize) {
        Page<QyYlgyssjYjxxParamBo> page = new Page<>(pageNo, pageSize);
        /*LambdaQueryWrapper<SpcyQyYlgyssj> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyYlgyssj.getFqyid()),SpcyQyYlgyssj::getFqyid,spcyQyYlgyssj.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFwjlx1()),SpcyQyYlgyssj::getFwjlx1,spcyQyYlgyssj.getFwjlx1());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFwjlx2()),SpcyQyYlgyssj::getFwjlx2,spcyQyYlgyssj.getFwjlx2());

        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFwlmc()),SpcyQyYlgyssj::getFwlmc,spcyQyYlgyssj.getFwlmc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFwlfl()),SpcyQyYlgyssj::getFwlfl,spcyQyYlgyssj.getFwlfl());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFjxsmc()),SpcyQyYlgyssj::getFjxsmc,spcyQyYlgyssj.getFjxsmc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFgg()),SpcyQyYlgyssj::getFgg,spcyQyYlgyssj.getFgg());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFgysdz()),SpcyQyYlgyssj::getFgysdz,spcyQyYlgyssj.getFgysdz());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFgyslb()),SpcyQyYlgyssj::getFgyslb,spcyQyYlgyssj.getFgyslb());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFscsdz()),SpcyQyYlgyssj::getFscsdz,spcyQyYlgyssj.getFscsdz());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFscsmc()),SpcyQyYlgyssj::getFscsmc,spcyQyYlgyssj.getFscsmc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFtymc()),SpcyQyYlgyssj::getFtymc,spcyQyYlgyssj.getFtymc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyYlgyssj.getFzlbz()),SpcyQyYlgyssj::getFzlbz,spcyQyYlgyssj.getFzlbz());*/

        IPage<QyYlgyssjYjxxParamBo> pageList = this.getWlxxPageList(page, spcyQyYlgyssj);
        return HttpResult.ok(pageList);
    }

    /** 物料分页列表 */
    private IPage<QyYlgyssjYjxxParamBo> getWlxxPageList(Page<QyYlgyssjYjxxParamBo> page, QyYlgyssjYjxxParamBo zjxx){
        if (StringUtils.isNotBlank(zjxx.getSfgq())){
            if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX)){
                zjxx.setCqyx(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX);

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_WGQ)){
                zjxx.setWgq(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ)){
                zjxx.setYgqsj(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ)){
                // 提交几个月进行预警
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
                zjxx.setWgq(DateUtil.today());
                zjxx.setJjgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX)){
                // 几个月以上有效
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
                zjxx.setWgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }
        }

        zjxx.setNowDay(DateUtil.today());

        Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
        zjxx.setGqDay(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

        Date yxDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
        zjxx.setYxDay(DateConversionUtils.DateToStringYYYYMMDD(yxDate));

        IPage<QyYlgyssjYjxxParamBo> pageList = spcyQyYlgyssjMapper.findWlyjPageList(page, zjxx);

        return pageList;
    }

    /** 物料列表 */
    private List<QyYlgyssjYjxxParamBo> getWlxxList(QyYlgyssjYjxxParamBo zjxx){
        if (StringUtils.isNotBlank(zjxx.getSfgq())){
            if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX)){
                zjxx.setCqyx(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX);

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_WGQ)){
                zjxx.setWgq(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ)){
                zjxx.setYgqsj(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ)){
                // 提交几个月进行预警
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
                zjxx.setWgq(DateUtil.today());
                zjxx.setJjgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX)){
                // 几个月以上有效
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
                zjxx.setWgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }
        }

        zjxx.setNowDay(DateUtil.today());

        Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
        zjxx.setGqDay(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

        Date yxDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
        zjxx.setYxDay(DateConversionUtils.DateToStringYYYYMMDD(yxDate));

        List<QyYlgyssjYjxxParamBo> pageList = spcyQyYlgyssjMapper.findAllWlyjList(zjxx);

        return pageList;
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addYlgyssj(SpcyQyYlgyssj jbxx, boolean onlyCurrentUser){
        jbxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            jbxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(jbxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        if (StringUtils.isNotBlank(jbxx.getFscsmc())){
            jbxx.setFjxsmc(jbxx.getFscsmc());
        }
        spcyQyYlgyssjService.save(jbxx);

        String log = "添加-企业-原料供应商审计：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(jbxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,jbxx.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(jbxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateYlgyssj(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyYlgyssj Update = spcyQyYlgyssjService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);

        if (StringUtils.isNotBlank(Update.getFscsmc())){
            Update.setFjxsmc(Update.getFscsmc());
        }
        spcyQyYlgyssjService.updateById(Update);

        String operContent = "企业-原料供应商审计-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteYlgyssj(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyYlgyssj> sqsxWjmlList = spcyQyYlgyssjService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyYlgyssj wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyYlgyssjService.removeById(id);
            this.deleteInfoFileByFpid(id);

            operContent = "删除-原料供应商审计：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryYlgyssjById(String id) {
        SpcyQyYlgyssj jbxx = spcyQyYlgyssjService.getById(id);
        return HttpResult.ok(jbxx);
    }

    /************************************[ 企业-设备确认信息 ]**************************************************************************/
    /**
     * 分页查询
     */
    public HttpResult<?> querySbqrxxPageList(SpcyQySbqrxx spcyQySbqrxx, Integer pageNo, Integer pageSize) {
        Page<SpcyQySbqrxx> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQySbqrxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQySbqrxx.getFqyid()),SpcyQySbqrxx::getFqyid,spcyQySbqrxx.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQySbqrxx.getFyzmc()),SpcyQySbqrxx::getFyzmc,spcyQySbqrxx.getFyzmc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQySbqrxx.getFyzfabh()),SpcyQySbqrxx::getFyzfabh,spcyQySbqrxx.getFyzfabh());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQySbqrxx.getFyzbgbh()),SpcyQySbqrxx::getFyzbgbh,spcyQySbqrxx.getFyzbgbh());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQySbqrxx.getFbz()),SpcyQySbqrxx::getFbz,spcyQySbqrxx.getFbz());

        queryWrapper.orderByDesc(SpcyQySbqrxx::getCreateTime);
        IPage<SpcyQySbqrxx> pageList = spcyQySbqrxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }
    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addSbqrxx(SpcyQySbqrxx sbqrxx, boolean onlyCurrentUser){
        sbqrxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            sbqrxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(sbqrxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQySbqrxxService.save(sbqrxx);

        String log = "添加-企业-设备确认信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(sbqrxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,sbqrxx.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(sbqrxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateSbqrxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQySbqrxx Update = spcyQySbqrxxService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQySbqrxxService.updateById(Update);

        String operContent = "企业-设备确认信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteSbqrxx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQySbqrxx> sqsxWjmlList = spcyQySbqrxxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQySbqrxx wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQySbqrxxService.removeById(id);
            this.deleteInfoFileByFpid(id);

            operContent = "删除-设备确认信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> querySbqrxxById(String id) {
        SpcyQySbqrxx sbqrxx = spcyQySbqrxxService.getById(id);
        return HttpResult.ok(sbqrxx);
    }

    /************************************[ 企业-产品偏差信息 ]**************************************************************************/
    /**
     * 分页查询
     */
    public HttpResult<?> queryCppcxxPageList(SpcyQyCppcxx spcyQyCppcxx, StartEndDateVo startEndDateVo, Integer pageNo, Integer pageSize) {
        Page<SpcyQyCppcxx> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyCppcxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyCppcxx.getFpcbh()),SpcyQyCppcxx::getFpcbh,spcyQyCppcxx.getFpcbh());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFqyid()),SpcyQyCppcxx::getFqyid,spcyQyCppcxx.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFjjcsbjcs()),SpcyQyCppcxx::getFjjcsbjcs,spcyQyCppcxx.getFjjcsbjcs());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFjzyfcs()),SpcyQyCppcxx::getFjzyfcs,spcyQyCppcxx.getFjzyfcs());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFbz()),SpcyQyCppcxx::getFbz,spcyQyCppcxx.getFbz());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFpcjb()),SpcyQyCppcxx::getFpcjb,spcyQyCppcxx.getFpcjb());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFpczt()),SpcyQyCppcxx::getFpczt,spcyQyCppcxx.getFpczt());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFpcbm()),SpcyQyCppcxx::getFpcbm,spcyQyCppcxx.getFpcbm());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFpcjs()),SpcyQyCppcxx::getFpcjs,spcyQyCppcxx.getFpcjs());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFgbyy()),SpcyQyCppcxx::getFgbyy,spcyQyCppcxx.getFgbyy());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyCppcxx.getFsyxdcphwl()),SpcyQyCppcxx::getFsyxdcphwl,spcyQyCppcxx.getFsyxdcphwl());

        if (spcyQyCppcxx.getFfxrq() != null){
            queryWrapper.ge(SpcyQyCppcxx::getFfxrq, spcyQyCppcxx.getFfxrq());
        }

        if (spcyQyCppcxx.getFgbrq() != null){
            queryWrapper.ge(SpcyQyCppcxx::getFgbrq, spcyQyCppcxx.getFgbrq());
        }

        if (startEndDateVo.getKssj() != null){
//            queryWrapper.ge(SpcyQyCppcxx::getFfxrq, startEndDateVo.getKssj());
            queryWrapper.apply("to_char(ffxrq,'yyyy-mm-dd') >= {0}",DateConversionUtils.DateToStringYYYYMMDD(startEndDateVo.getKssj()));

        }
        if (startEndDateVo.getJssj() != null){
//            queryWrapper.le(SpcyQyCppcxx::getFfxrq, startEndDateVo.getJssj());
            queryWrapper.apply("to_char(ffxrq,'yyyy-mm-dd') <= {0}",DateConversionUtils.DateToStringYYYYMMDD(startEndDateVo.getJssj()));

        }

        queryWrapper.orderByDesc(SpcyQyCppcxx::getCreateTime);
        IPage<SpcyQyCppcxx> pageList = spcyQyCppcxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addCppcxx(SpcyQyCppcxx cppcxx, boolean onlyCurrentUser){
        cppcxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            cppcxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(cppcxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyCppcxxService.save(cppcxx);

        String log = "添加-企业-产品偏差信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(cppcxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,cppcxx.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(cppcxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateCppcxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyCppcxx Update = spcyQyCppcxxService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyCppcxxService.updateById(Update);

        String operContent = "企业-产品偏差信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteCppcxx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyCppcxx> sqsxWjmlList = spcyQyCppcxxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyCppcxx wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyCppcxxService.removeById(id);

            this.deleteInfoFileByFpid(id);

            operContent = "删除-产品偏差信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryCppcxxById(String id) {
        SpcyQyCppcxx cppcxx = spcyQyCppcxxService.getById(id);
        return HttpResult.ok(cppcxx);
    }

    /************************************[ 企业-变更控制 ]**************************************************************************/
    /**
     * 分页查询
     */
    public HttpResult<?> queryBgkzPageList(SpcyQyBgkz bgkz, StartEndDateVo startEndDateVo, Integer pageNo, Integer pageSize) {
        Page<SpcyQyBgkz> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyBgkz> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFqyid()),SpcyQyBgkz::getFqyid,bgkz.getFqyid());
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFbgbh()),SpcyQyBgkz::getFbgbh,bgkz.getFbgbh());
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFbgfl()),SpcyQyBgkz::getFbgfl,bgkz.getFbgfl());
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFbgjl()),SpcyQyBgkz::getFbgjl,bgkz.getFbgjl());
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFbgkz()),SpcyQyBgkz::getFbgkz,bgkz.getFbgkz());
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFssbm()),SpcyQyBgkz::getFssbm,bgkz.getFssbm());
        queryWrapper.eq(StringUtils.isNotBlank(bgkz.getFbgzt()),SpcyQyBgkz::getFbgzt,bgkz.getFbgzt());


        if (bgkz.getFbgrq() != null){
            queryWrapper.ge(SpcyQyBgkz::getFbgrq,bgkz.getFbgrq());
        }

        if (startEndDateVo.getKssj() != null){
//            queryWrapper.ge(SpcyQyBgkz::getFbgrq,startEndDateVo.getKssj());
            queryWrapper.apply("to_char(fbgrq,'yyyy-mm-dd') >= {0}",DateConversionUtils.DateToStringYYYYMMDD(startEndDateVo.getKssj()));
        }
        if (startEndDateVo.getJssj() != null){
//            queryWrapper.le(SpcyQyBgkz::getFbgrq,startEndDateVo.getJssj());
            queryWrapper.apply("to_char(fbgrq,'yyyy-mm-dd') <= {0}", DateConversionUtils.DateToStringYYYYMMDD(startEndDateVo.getJssj()));
        }

        queryWrapper.orderByDesc(SpcyQyBgkz::getCreateTime);
        IPage<SpcyQyBgkz> pageList = spcyQyBgkzService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addBgkz(SpcyQyBgkz bgkz, boolean onlyCurrentUser){
        bgkz.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            bgkz.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(bgkz.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyBgkzService.save(bgkz);

        String log = "添加-企业-变更控制信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bgkz));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,bgkz.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(bgkz);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateBgkz(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyBgkz Update = spcyQyBgkzService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyBgkzService.updateById(Update);

        String operContent = "企业-变更控制-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteBgkz(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyBgkz> sqsxWjmlList = spcyQyBgkzService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyBgkz wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyCppcxxService.removeById(id);

            this.deleteInfoFileByFpid(id);

            operContent = "删除-变更控制信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryBgkzById(String id) {
        SpcyQyBgkz bgkz = spcyQyBgkzService.getById(id);
        return HttpResult.ok(bgkz);
    }

    /************************************[ 企业-清洁验证 ]**************************************************************************/
    /**
     * 分页查询
     */
    public HttpResult<?> queryQjyzPageList(SpcyQyQjyz spcyQyQjyz, Integer pageNo, Integer pageSize) {
        Page<SpcyQyQjyz> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyQjyz> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyQjyz.getFqyid()),SpcyQyQjyz::getFqyid,spcyQyQjyz.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyQjyz.getFyzmc()),SpcyQyQjyz::getFyzmc,spcyQyQjyz.getFyzmc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyQjyz.getFyzfabh()),SpcyQyQjyz::getFyzfabh,spcyQyQjyz.getFyzfabh());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyQjyz.getFyzbgbh()),SpcyQyQjyz::getFyzbgbh,spcyQyQjyz.getFyzbgbh());

        queryWrapper.orderByDesc(SpcyQyQjyz::getForder);
        queryWrapper.orderByDesc(SpcyQyQjyz::getCreateTime);
        IPage<SpcyQyQjyz> pageList = spcyQyQjyzService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addQjyz(SpcyQyQjyz qjyz, boolean onlyCurrentUser){
        qjyz.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            qjyz.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(qjyz.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }

        List<SpcyQyQjyz> sizeList = spcyQyQjyzService.list(new LambdaQueryWrapper<SpcyQyQjyz>()
                .eq(SpcyQyQjyz::getFqyid, qjyz.getFqyid()));
        int count = sizeList.size() + 1;
        qjyz.setForder(count);
        spcyQyQjyzService.save(qjyz);

        String log = "添加-企业-清洁验证：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(qjyz));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,qjyz.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(qjyz);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateQjyz(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyQjyz Update = spcyQyQjyzService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyQjyzService.updateById(Update);

        String operContent = "企业-清洁验证-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteQjyz(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyQjyz> sqsxWjmlList = spcyQyQjyzService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyQjyz wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyQjyzService.removeById(id);
            this.deleteInfoFileByFpid(id);

            operContent = "删除-清洁验证：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryQjyzById(String id) {
        SpcyQyQjyz qjyz = spcyQyQjyzService.getById(id);
        return HttpResult.ok(qjyz);
    }
    /************************************[ 企业-工艺验证 ]**************************************************************************/
    /**
     * 分页查询
     */
    public HttpResult<?> queryQyGyyzPageList(SpcyQyGyyz spcyQyGyyz, Integer pageNo, Integer pageSize) {
        Page<SpcyQyGyyz> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyGyyz> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyGyyz.getFqyid()),SpcyQyGyyz::getFqyid,spcyQyGyyz.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyGyyz.getFyzmc()),SpcyQyGyyz::getFyzmc,spcyQyGyyz.getFyzmc());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyGyyz.getFyzfabh()),SpcyQyGyyz::getFyzfabh,spcyQyGyyz.getFyzfabh());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyGyyz.getFyzbgbh()),SpcyQyGyyz::getFyzbgbh,spcyQyGyyz.getFyzbgbh());

        queryWrapper.orderByDesc(SpcyQyGyyz::getCreateTime);
        IPage<SpcyQyGyyz> pageList = spcyQyGyyzService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addGyyz(SpcyQyGyyz gyyz, boolean onlyCurrentUser){
        gyyz.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            gyyz.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(gyyz.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyGyyzService.save(gyyz);

        String log = "添加-企业-工艺验证：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(gyyz));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,gyyz.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(gyyz);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateGyyz(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyGyyz Update = spcyQyGyyzService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyGyyzService.updateById(Update);

        String operContent = "企业-工艺验证-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteGyyz(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyGyyz> sqsxWjmlList = spcyQyGyyzService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyGyyz wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyGyyzService.removeById(id);
            this.deleteInfoFileByFpid(id);

            operContent = "删除-工艺验证：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryGyyzById(String id) {
        SpcyQyGyyz gyyz = spcyQyGyyzService.getById(id);
        return HttpResult.ok(gyyz);
    }
    /************************************[ 企业-检查信息 ]**************************************************************************/
    /**
     * 分页查询
     */
    public HttpResult<?> queryQyJcxxPageList(SpcyQyJcxx spcyQyJcxx, Integer pageNo, Integer pageSize) {
        Page<SpcyQyJcxx> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyJcxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(spcyQyJcxx.getFqyid()),SpcyQyJcxx::getFqyid,spcyQyJcxx.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyJcxx.getFjclx()),SpcyQyJcxx::getFjclx,spcyQyJcxx.getFjclx());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyJcxx.getFjcry()),SpcyQyJcxx::getFjcry,spcyQyJcxx.getFjcry());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyJcxx.getFzgqk()),SpcyQyJcxx::getFzgqk,spcyQyJcxx.getFzgqk());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyJcxx.getFjcjl()),SpcyQyJcxx::getFjcjl,spcyQyJcxx.getFjcjl());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyJcxx.getFwjlx1()),SpcyQyJcxx::getFwjlx1,spcyQyJcxx.getFwjlx1());
        queryWrapper.like(StringUtils.isNotEmpty(spcyQyJcxx.getFwjlx2()),SpcyQyJcxx::getFwjlx2,spcyQyJcxx.getFwjlx2());

        queryWrapper.orderByDesc(SpcyQyJcxx::getCreateTime);
        IPage<SpcyQyJcxx> pageList = spcyQyJcxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addQyJcxx(SpcyQyJcxx qyJcxx, boolean onlyCurrentUser){
        qyJcxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            qyJcxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(qyJcxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        spcyQyJcxxService.save(qyJcxx);

        String log = "添加-企业-检查信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(qyJcxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,qyJcxx.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(qyJcxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateJcxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyJcxx Update = spcyQyJcxxService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyJcxxService.updateById(Update);

        String operContent = "企业-检查信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteJcxx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyJcxx> sqsxWjmlList = spcyQyJcxxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyJcxx wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyJcxxService.removeById(id);
            this.deleteInfoFileByFpid(id);

            operContent = "删除-企业品种基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryJcxxById(String id) {
        SpcyQyJcxx jcxx = spcyQyJcxxService.getById(id);
        return HttpResult.ok(jcxx);
    }

    /************************************[ 企业-证件信息 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryQyZjxxPageList(QyZjyjxxParamBo zjxx, Integer pageNo, Integer pageSize) {
        Page<QyZjyjxxParamBo> page = new Page<>(pageNo, pageSize);

        return HttpResult.ok(this.getZjxxPageList(page, zjxx));
    }

    /** 证件分页查询 */
    private IPage<QyZjyjxxParamBo> getZjxxPageList(Page<QyZjyjxxParamBo> page,QyZjyjxxParamBo zjxx){
        if (StringUtils.isNotBlank(zjxx.getSfgq())){
            if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX)){
                zjxx.setCqyx(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX);

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_WGQ)){
                zjxx.setWgq(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ)){
                zjxx.setYgqsj(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ)){
                // 提交几个月进行预警
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
                zjxx.setWgq(DateUtil.today());
                zjxx.setJjgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX)){
                // 几个月以上有效
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
                zjxx.setWgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }
        }

        zjxx.setNowDay(DateUtil.today());

        Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
        zjxx.setGqDay(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

        Date yxDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
        zjxx.setYxDay(DateConversionUtils.DateToStringYYYYMMDD(yxDate));

        IPage<QyZjyjxxParamBo> pageList = spcyQyZjxxMapper.findZjyjPageList(page, zjxx);

        return pageList;
    }

    /** 证件分页查询 */
    private IPage<SpcyQyZjxx> selectZjxxPage(Page<SpcyQyZjxx> page,SpcyQyZjxx zjxx){
//        --UPDATE spcy_qy_zjxx SET fsfgq = '长期' WHERE fzjyxq IS NULL;
//        --UPDATE spcy_qy_zjxx SET fsfgq = '未过期' WHERE fzjyxq >= '2022-08-01';
//        --UPDATE spcy_qy_zjxx SET fsfgq = '过期' WHERE fzjyxq < '2022-08-01';
//        --UPDATE spcy_qy_zjxx SET fyxzt = '到期自动注销' WHERE fzjyxq < '2022-08-01' AND fyxzt = '有效';

        return spcyQyZjxxService.page(page, new LambdaQueryWrapper<SpcyQyZjxx>()
                .like(StringUtils.isNotBlank(zjxx.getFqyid()), SpcyQyZjxx::getFqyid, zjxx.getFqyid())
                .like(StringUtils.isNotBlank(zjxx.getFzjbh()), SpcyQyZjxx::getFzjbh, zjxx.getFzjbh())
                .like(StringUtils.isNotBlank(zjxx.getFzjmc()), SpcyQyZjxx::getFzjmc, zjxx.getFzjmc())
                .eq(StringUtils.isNotBlank(zjxx.getFyxzt()), SpcyQyZjxx::getFyxzt, zjxx.getFyxzt())
        );
    }

    /** 证件列表 */
    private List<QyZjyjxxParamBo> getZjxxList(QyZjyjxxParamBo zjxx){
        if (StringUtils.isNotBlank(zjxx.getSfgq())){
            if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX)){
                zjxx.setCqyx(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX);

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_WGQ)){
                zjxx.setWgq(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ)){
                zjxx.setYgqsj(DateUtil.today());

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ)){
                // 提交几个月进行预警
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
                zjxx.setWgq(DateUtil.today());
                zjxx.setJjgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }else if (zjxx.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX)){
                // 几个月以上有效
                Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
                zjxx.setWgq(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

            }
        }

        zjxx.setNowDay(DateUtil.today());

        Date gqDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ_MONTH);
        zjxx.setGqDay(DateConversionUtils.DateToStringYYYYMMDD(gqDate));

        Date yxDate = DateUtil.offsetMonth(new Date(), SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX_MONTH);
        zjxx.setYxDay(DateConversionUtils.DateToStringYYYYMMDD(yxDate));

        List<QyZjyjxxParamBo> pageList = spcyQyZjxxMapper.findAllZjList(zjxx);

        return pageList;
    }

    /**
     * 添加证件
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addZjxx(SpcyQyZjxx zjxx, boolean onlyCurrentUser){
        zjxx.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            zjxx.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(zjxx.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员!");
            }
        }
        if (StringUtils.isBlank(zjxx.getFyxzt())) {
            zjxx.setFyxzt(SpcyCommonConstant.QY_ZJXX_YXZT_YX);
        }
        spcyQyZjxxService.save(zjxx);

        String log = "添加-企业-证件信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(zjxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,zjxx.getFqyid(), "添加企业证件",SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(zjxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateZjxx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }

        String wjmlId = buffer.get("id");
        SpcyQyZjxx Update = spcyQyZjxxService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyZjxxService.updateById(Update);

        String operContent = "企业-证件信息-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,"修改企业证件信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteZjxx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = StringPatternUtils.getListByIds(ids);
        List<SpcyQyZjxx> sqsxWjmlList = spcyQyZjxxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyZjxx wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyZjxxService.removeById(id);
            this.deleteInfoFileByFpid(id);

            operContent = "删除-企业证件基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjml.getFqyid(),"删除企业证件",SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 获取文件列表-根据业务id
     * @param fpid 业务id
     */
    public List<SpcyQyWjjl> queryQyFileList(String fpid){
        if (StringUtils.isBlank(fpid)){
            fpid = "0";
        }
        List<SpcyQyWjjl> list = spcyQyWjjlService.list(new LambdaQueryWrapper<SpcyQyWjjl>()
                .eq(SpcyQyWjjl::getFpid, fpid)
                .orderByAsc(SpcyQyWjjl::getCreateTime));

        return list;
    }

    /************************************[ 企业-生产车间 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> querySccjPageList(SpcyQySccj query, Integer pageNo, Integer pageSize) {
        Page<SpcyQySccj> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQySccj> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()),SpcyQySccj::getFqyid,query.getFqyid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFpzid()),SpcyQySccj::getFpzid,query.getFpzid());
        queryWrapper.like(StringUtils.isNotBlank(query.getFcjbh()),SpcyQySccj::getFcjbh,query.getFcjbh());
        queryWrapper.like(StringUtils.isNotBlank(query.getFcjmc()),SpcyQySccj::getFcjmc,query.getFcjmc());
        queryWrapper.like(StringUtils.isNotBlank(query.getFfzr()),SpcyQySccj::getFfzr,query.getFfzr());
        queryWrapper.like(StringUtils.isNotBlank(query.getFqyfl()),SpcyQySccj::getFqyfl,query.getFqyfl());
        queryWrapper.like(StringUtils.isNotBlank(query.getId()),SpcyQySccj::getId,query.getId());
        queryWrapper.eq(SpcyQySccj::getFyxzt, SpcyCommonConstant.QY_RELATED_YXZT_YX);

        queryWrapper.orderByDesc(SpcyQySccj::getCreateTime);
        IPage<SpcyQySccj> pageList = spcyQySccjService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addSccj(SpcyQySccj bean, boolean onlyCurrentUser){
        bean.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            bean.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(bean.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        if (bean.getFyjz() == null){
            bean.setFyjz(0);
        }
        if (bean.getFcbz() == null){
            bean.setFcbz(0);
        }
        bean.setFyxzt(SpcyCommonConstant.QY_RELATED_YXZT_YX);
        spcyQySccjService.save(bean);

        String log = "添加-企业-生产车间信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFqyid(), "添加-企业-生产车间信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(bean);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateSccj(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQySccj Update = spcyQySccjService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQySccjService.updateById(Update);

        String operContent = "修改企业生产车间信息：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, Update.getFqyid(),"修改企业生产车间信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteSccj(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空！");
        }

        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQySccj> list = spcyQySccjService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            return HttpResult.error("当前数据不存在！");
        }

        String operContent = "";
        for (SpcyQySccj bean : list){
            bean.setFyxzt(SpcyCommonConstant.QY_RELATED_YXZT_WX);
            spcyQySccjService.updateById(bean);

            // 删除环境记录
            this.deleteSccjHjjlByScId(bean.getId());

            operContent = "";
            operContent = "删除-企业生产车间基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(bean);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, bean.getFqyid(),"删除-企业生产车间基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
        }
        return HttpResult.ok("删除成功");
    }

    /**
     * 删除生产车间使用记录
     */
    public void deleteSccjSyjl(String fsccjid){
        if (StringUtils.isBlank(fsccjid)){
            throw new BusinessException("生产记录数据参数为空！");
        }
        List<SpcyQySccjjl> list = spcyQySccjjlService.list(new LambdaQueryWrapper<SpcyQySccjjl>()
                .eq(SpcyQySccjjl::getFscjlid, fsccjid));

        if (CollectionUtil.isEmpty(list)){
            return;
        }
        String operContent = "";
        for (SpcyQySccjjl sccjjl : list){

            spcyQySccjjlService.removeById(sccjjl.getId());

            operContent = "";
            operContent = "删除-企业生产车间记录信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(sccjjl);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, sccjjl.getFscjlid(),"删除-企业生产车间记录信息",SpcyConstant.LOGS_SYS_TYPE_SC);

        }

    }

    /************************************[ 企业-生产工艺 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryScgyPageList(SpcyQyScgy query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyScgy> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyScgy> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFpzid()),SpcyQyScgy::getFpzid,query.getFpzid());

        queryWrapper.orderByDesc(SpcyQyScgy::getCreateTime);
        IPage<SpcyQyScgy> pageList = spcyQyScgyService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addScgy(SpcyQyScgy bean, boolean onlyCurrentUser){
        if (StringUtils.isBlank(bean.getFpzid())){
            return HttpResult.error("品种参数为空！");
        }
        bean.setId(GetUuIdUtils.ReplaceUuId());
        spcyQyScgyService.save(bean);

        String log = "添加-企业-生产工艺信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFpzid(), "添加-企业-生产工艺信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        return HttpResultVo.HttpResultSave(bean, "保存成功");
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateScgy(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyScgy Update = spcyQyScgyService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyScgyService.updateById(Update);

        String operContent = "修改企业生产工艺信息：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, Update.getFpzid(),"修改企业生产工艺信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteScgy(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空！");
        }

        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyScgy> list = spcyQyScgyService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            return HttpResult.error("当前数据不存在！");
        }

        spcyQyScgyService.removeBatchByIds(idsList);

        String operContent = "";
        for (SpcyQyScgy bean : list){
            operContent = "";
            operContent = "删除-企业生产工艺基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(bean);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, bean.getFpzid(),"删除-企业生产工艺基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
        }
        return HttpResult.ok("删除成功");
    }

    /************************************[ 企业-药品生产状况 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryYpsczkPageList(SpcyQyYpsczk query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyYpsczk> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyYpsczk> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFpzid()),SpcyQyYpsczk::getFpzid,query.getFpzid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFscnf()),SpcyQyYpsczk::getFscnf,query.getFscnf());

        queryWrapper.orderByAsc(SpcyQyYpsczk::getFscnf);
        IPage<SpcyQyYpsczk> pageList = spcyQyYpsczkService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addYpsczk(SpcyQyYpsczk bean, boolean onlyCurrentUser){
        if (StringUtils.isBlank(bean.getFpzid())){
            return HttpResult.error("品种参数为空！");
        }

        if (StringUtils.isBlank(bean.getFscnf())){
            bean.setFscnf(DateConversionUtils.DateToYear(new Date()));
        }

        if (CollectionUtil.isNotEmpty(spcyQyYpsczkService.list(new LambdaQueryWrapper<SpcyQyYpsczk>()
                .eq(SpcyQyYpsczk::getFpzid, bean.getFpzid())
                .eq(SpcyQyYpsczk::getFscnf, bean.getFscnf())))){
            return HttpResult.error(bean.getFscnf() + "药品生产状况已经存在！");
        }

        bean.setId(GetUuIdUtils.ReplaceUuId());
        spcyQyYpsczkService.save(bean);

        String log = "添加-企业-药品生产状况信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFpzid(), "添加-企业-药品生产状况信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        return HttpResultVo.HttpResultSave(bean, "保存成功");
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateYpsczk(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyYpsczk Update = spcyQyYpsczkService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyYpsczkService.updateById(Update);

        String operContent = "修改企业药品生产状况信息：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, Update.getFpzid(),"修改企业药品生产状况信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteYpsczk(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空！");
        }

        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyYpsczk> list = spcyQyYpsczkService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            return HttpResult.error("当前数据不存在！");
        }

        spcyQyYpsczkService.removeBatchByIds(idsList);

        String operContent = "";
        for (SpcyQyYpsczk bean : list){
            operContent = "";
            operContent = "删除-企业药品生产状况基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(bean);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, bean.getFpzid(),"删除-企业药品生产状况基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
        }
        return HttpResult.ok("删除成功");
    }

    /************************************[ 企业-药品委托生产 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryYpwtscPageList(SpcyQyYpwtsc query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyYpwtsc> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyYpwtsc> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFpzid()),SpcyQyYpwtsc::getFpzid,query.getFpzid());

        queryWrapper.orderByAsc(SpcyQyYpwtsc::getCreateTime);
        IPage<SpcyQyYpwtsc> pageList = spcyQyYpwtscService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addYpwtsc(SpcyQyYpwtsc bean, boolean onlyCurrentUser){
        if (StringUtils.isBlank(bean.getFpzid())){
            return HttpResult.error("品种参数为空！");
        }

        bean.setId(GetUuIdUtils.ReplaceUuId());
        spcyQyYpwtscService.save(bean);

        String log = "添加-企业-药品委托生产信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFpzid(), "添加-企业-药品委托生产信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        return HttpResultVo.HttpResultSave(bean, "保存成功");
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateYpwtsc(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyYpwtsc Update = spcyQyYpwtscService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyYpwtscService.updateById(Update);

        String operContent = "修改企业-药品委托生产信息：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, Update.getFpzid(),"修改企业-药品委托生产信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteYpwtsc(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空！");
        }

        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyYpwtsc> list = spcyQyYpwtscService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            return HttpResult.error("当前数据不存在！");
        }

        spcyQyYpwtscService.removeBatchByIds(idsList);

        String operContent = "";
        for (SpcyQyYpwtsc bean : list){
            operContent = "";
            operContent = "删除企业-药品委托生产基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(bean);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, bean.getFpzid(),"删除企业-药品委托生产基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
        }
        return HttpResult.ok("删除成功");
    }

    /************************************[ 企业-产值 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult queryCzPageList(SpcyQyCz query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyCz> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyCz> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFnf()),SpcyQyCz::getFnf,query.getFnf());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()),SpcyQyCz::getFqyid,query.getFqyid());

        queryWrapper.orderByAsc(SpcyQyCz::getFnf);
        IPage<SpcyQyCz> pageList = spcyQyCzService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addCz(SpcyQyCz bean, boolean onlyCurrentUser){
        if (StringUtils.isBlank(bean.getFqyid())){
            return HttpResult.error("企业参数为空！");
        }

        if (StringUtils.isBlank(bean.getFnf())){
            bean.setFnf(DateConversionUtils.DateToYear(new Date()));
        }

        if (CollectionUtil.isNotEmpty(spcyQyCzService.list(new LambdaQueryWrapper<SpcyQyCz>()
                .eq(SpcyQyCz::getFqyid, bean.getFqyid())
                .eq(SpcyQyCz::getFnf, bean.getFnf())))){
            return HttpResult.error(bean.getFnf() + "产值已经存在！");
        }

        bean.setId(GetUuIdUtils.ReplaceUuId());
        spcyQyCzService.save(bean);

        String log = "添加-企业-产值信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFqyid(), "添加-企业-产值信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        return HttpResultVo.HttpResultSave(bean, "保存成功");
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateCz(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyCz Update = spcyQyCzService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyCzService.updateById(Update);

        String operContent = "修改企业产值信息：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, Update.getFqyid(),"修改企业产值信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteCz(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空！");
        }

        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyCz> list = spcyQyCzService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            return HttpResult.error("当前数据不存在！");
        }

        spcyQyCzService.removeBatchByIds(idsList);

        String operContent = "";
        for (SpcyQyCz bean : list){
            operContent = "";
            operContent = "删除-企业产值基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(bean);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, bean.getFqyid(),"删除-企业产值基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
        }
        return HttpResult.ok("删除成功");
    }

    /************************************[ 企业-研发投入]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult queryYftrPageList(SpcyQyYftr query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyYftr> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyYftr> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFnf()),SpcyQyYftr::getFnf,query.getFnf());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()),SpcyQyYftr::getFqyid,query.getFqyid());

        queryWrapper.orderByAsc(SpcyQyYftr::getFnf);
        IPage<SpcyQyYftr> pageList = spcyQyYftrService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addYftr(SpcyQyYftr bean, boolean onlyCurrentUser){
        if (StringUtils.isBlank(bean.getFqyid())){
            return HttpResult.error("企业参数为空！");
        }

        if (StringUtils.isBlank(bean.getFnf())){
            bean.setFnf(DateConversionUtils.DateToYear(new Date()));
        }

        if (CollectionUtil.isNotEmpty(spcyQyYftrService.list(new LambdaQueryWrapper<SpcyQyYftr>()
                .eq(SpcyQyYftr::getFqyid, bean.getFqyid())
                .eq(SpcyQyYftr::getFnf, bean.getFnf())))){
            return HttpResult.error(bean.getFnf() + "研发投入已经存在！");
        }

        bean.setId(GetUuIdUtils.ReplaceUuId());
        spcyQyYftrService.save(bean);

        String log = "添加-企业-研发投入信息：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFqyid(), "添加-企业-研发投入信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

        return HttpResultVo.HttpResultSave(bean, "保存成功");
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateYftr(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyYftr Update = spcyQyYftrService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyYftrService.updateById(Update);

        String operContent = "修改企业研发投入信息：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, Update.getFqyid(),"修改企业研发投入信息",SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteYftr(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("参数为空！");
        }

        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyYftr> list = spcyQyYftrService.listByIds(idsList);
        if (CollectionUtils.isEmpty(list)){
            return HttpResult.error("当前数据不存在！");
        }

        spcyQyYftrService.removeBatchByIds(idsList);

        String operContent = "";
        for (SpcyQyYftr bean : list){
            operContent = "";
            operContent = "删除-企业研发投入基本信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(bean);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, bean.getFqyid(),"删除-企业研发投入基本信息",SpcyConstant.LOGS_SYS_TYPE_SC);
        }
        return HttpResult.ok("删除成功");
    }

    /************************************[ 企业-生产环境监控 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> querySccjHjjlPageList(SpcyQySchj query, Integer pageNo, Integer pageSize) {
        Page<SpcyQySchj> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQySchj> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()),SpcyQySchj::getFqyid,query.getFqyid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFsccjid()),SpcyQySchj::getFsccjid,query.getFsccjid());
        queryWrapper.like(StringUtils.isNotBlank(query.getFdjr()),SpcyQySchj::getFdjr,query.getFdjr());

        queryWrapper.orderByDesc(SpcyQySchj::getCreateTime);
        IPage<SpcyQySchj> pageList = spcyQySchjService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     *  添加车间环境监控记录
     */
    public void addSccjHjjl(SpcyQySchj schj){
        if (StringUtils.isBlank(schj.getFsccjid())){
            throw new BusinessException("车间参数为空！");
        }
        SpcyQySccj sccj = spcyQySccjService.getById(schj.getFsccjid());
        if (sccj == null){
            throw new BusinessException("没有想匹配的车间数据！");
        }
        if (schj.getFwswnd() == null){
            schj.setFwswnd(0);
        }
        schj.setFqyid(sccj.getFqyid());
        spcyQySchjService.save(schj);

        String log = "添加生产车间环境监控记录：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(schj));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,schj.getFqyid(),"添加生产车间环境监控记录",SpcyConstant.LOGS_SYS_TYPE_XZ);
    }

    /**
     * 删除车间环境监控记录
     * @param id 数据id
     */
    public void deleteSccjHjjl(String id){
        if(StringUtils.isBlank(id)){
            throw new BusinessException("数据参数为空！");
        }
        SpcyQySchj jl = spcyQySchjService.getById(id);
        if (jl == null){
            throw new BusinessException("没有想匹配的生产环境记录数据！");
        }
        spcyQySchjService.removeById(id);

        String log = "删除车间环境监控记录：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(jl));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, jl.getFqyid(), "删除车间环境监控记录", SpcyConstant.LOGS_SYS_TYPE_SC);
    }

    /**
     * 删除车间环境监控记录
     * @param fsccjid 生产车间id
     */
    public void deleteSccjHjjlByScId(String fsccjid){
        if (StringUtils.isBlank(fsccjid)){
            throw new BusinessException("车间数据参数为空！");
        }
        List<SpcyQySchj> list = spcyQySchjService.list(new LambdaQueryWrapper<SpcyQySchj>()
                .eq(SpcyQySchj::getFsccjid, fsccjid));
        if (CollectionUtil.isEmpty(list)){
            return;
        }
        for (SpcyQySchj schj : list){
            spcyQySchjService.removeById(schj.getId());

            String log = "删除车间环境监控记录：";
            log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(schj));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, schj.getFqyid(), "删除车间环境监控记录", SpcyConstant.LOGS_SYS_TYPE_SC);
        }
    }

    /************************************[ 企业-生产记录 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryScjlPageList(SpcyQyScjl query, Integer pageNo, Integer pageSize) {
        Page<SpcyQyScjl> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyScjl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()),SpcyQyScjl::getFqyid,query.getFqyid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFpzid()),SpcyQyScjl::getFpzid,query.getFpzid());
        queryWrapper.like(StringUtils.isNotBlank(query.getFbzgg()),SpcyQyScjl::getFbzgg,query.getFbzgg());
        queryWrapper.like(StringUtils.isNotBlank(query.getFcpph()),SpcyQyScjl::getFcpph,query.getFcpph());

        queryWrapper.like(StringUtils.isNotBlank(query.getFspm()),SpcyQyScjl::getFspm,query.getFspm());
        queryWrapper.like(StringUtils.isNotBlank(query.getFtymc()),SpcyQyScjl::getFtymc,query.getFtymc());
        queryWrapper.like(StringUtils.isNotBlank(query.getFcplb()),SpcyQyScjl::getFcplb,query.getFcplb());
        queryWrapper.like(StringUtils.isNotBlank(query.getFpzwh()),SpcyQyScjl::getFpzwh,query.getFpzwh());

        queryWrapper.orderByDesc(SpcyQyScjl::getCreateTime);
        IPage<SpcyQyScjl> pageList = spcyQyScjlService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加生产记录
     */
    public HttpResult addScjl(SpcyQyScjl scjl){
        if (StringUtils.isBlank(scjl.getFpzid())){
            throw new BusinessException("请选择对应品种！");
        }
        if (StringUtils.isBlank(scjl.getFcpph())){
            throw new BusinessException("产品批号为空！");
        }
        if (scjl.getFscrq() == null){
            throw new BusinessException("生产日期为空！");
        }
        SpcyQyPzjbxx pzjbxx = spcyQyPzjbxxService.getById(scjl.getFpzid());
        if (pzjbxx == null){
            throw new BusinessException("当前品种没有相匹配的数据！");
        }
        scjl.setFqyid(pzjbxx.getFqyid());
        scjl.setFspm(pzjbxx.getFspm());
        scjl.setFtymc(pzjbxx.getFtymc());
        scjl.setFcplb(pzjbxx.getFcplb());
        scjl.setFgg(pzjbxx.getFgg());
        scjl.setFpzwh(pzjbxx.getFpzwh());
        if (StringUtils.isBlank(scjl.getId())) {
            scjl.setId(GetUuIdUtils.ReplaceUuId());
            spcyQyScjlService.save(scjl);

            String log = "添加-企业生产记录信息：";
            log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(scjl));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, pzjbxx.getFqyid(), "添加-企业生产记录信息",SpcyConstant.LOGS_SYS_TYPE_XZ);
        }else {
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(scjl);
            spcyQyScjlService.updateById(scjl);

            String operContent = "修改企业生产记录信息：";
            operContent += LogUtils.BeanModifyMsg(scjl,oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, pzjbxx.getFqyid(), "修改企业生产记录信息",SpcyConstant.LOGS_SYS_TYPE_XZ);
        }

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(scjl);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 修改生产记录
     */
    public HttpResult updateScjl(HashMap<String, String> buffer)throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            throw new BusinessException("参数为空！");
        }
        String wjmlId = buffer.get("id");
        SpcyQyScjl updateBean = spcyQyScjlService.getById(wjmlId);
        if (updateBean == null){
            throw new BusinessException("当前数据没有相匹配的数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);

        if (StringUtils.isBlank(updateBean.getFpzid())){
            throw new BusinessException("请选择对应品种！");
        }
        if (StringUtils.isBlank(updateBean.getFcpph())){
            throw new BusinessException("产品批号为空！");
        }
        if (updateBean.getFscrq() == null){
            throw new BusinessException("生产日期为空！");
        }
        /*SpcyQyPzjbxx pzjbxx = spcyQyPzjbxxService.getById(updateBean.getFpzid());
        if (pzjbxx == null){
            throw new BusinessException("当前品种没有相匹配的数据！");
        }*/
        spcyQyScjlService.updateById(updateBean);

        String operContent = "修改企业生产记录信息：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, updateBean.getFqyid(),"修改企业生产记录信息",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除生产记录
     */
    public void deleteScjl(String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空！");
        }
        SpcyQyScjl scjl = spcyQyScjlService.getById(id);
        if (scjl == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        boolean flag = spcyQyScjlService.removeById(scjl.getId());
        if (flag) {
            // 删除生产车间记录
            this.deleteSccjSyjl(id);

            // 删除生产记录物料
            this.deleteScjlwl(null, id);

            // 删除文件
            this.deleteInfoFileByFpid(id);

            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(scjl);
            String operContent = LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, operContent, scjl.getId(), "删除-企业生产记录基本信息", SpcyConstant.LOGS_SYS_TYPE_SC);
        }
    }

    /**
     * 查询生产记录物料列表
     */
    public List<QyScjlWlParamBo> queryScjlWlList(String fscjlid){
        return spcyQyScjlMapper.findScjlWlList(fscjlid);
    }

    /**
     * 添加生产记录物料
     * @param fscjlid 生产记录id
     * @param kcid 物料库存id
     * @param fwlsysl 物料使用数量
     */
    public void addScjlWl(String fscjlid, String kcid, Integer fwlsysl){
        if (StringUtils.isBlank(fscjlid)){
            throw new BusinessException("生产记录参数为空！");
        }
        if (StringUtils.isBlank(kcid)){
            throw new BusinessException("物料参数为空！");
        }
        SpcyQyScjl scjl = spcyQyScjlService.getById(fscjlid);
        if (scjl == null){
            throw new BusinessException("没有相关匹配的生产记录数据！");
        }
        SpcyQyWlkc wlkc = spcyQyWlkcService.getById(kcid);
//        SpcyQyWlml wl = spcyQyWlmlService.getById(fwlmlid);
        if (wlkc == null){
            throw new BusinessException("没有相关匹配的物料库存数据！");
        }
        String fwlmlid = wlkc.getFwlmlid();

        SpcyQyScjlgx scjlgx = new SpcyQyScjlgx();
        scjlgx.setId(GetUuIdUtils.ReplaceUuId());
        scjlgx.setFwlsysl(Optional.ofNullable(fwlsysl).orElseGet(()->0));
        scjlgx.setFscjlid(fscjlid);
        scjlgx.setFwlmlid(fwlmlid);

//        SpcyQyWlkc wlkc = getWlkcByWlid(fwlmlid);

        List<SpcyQyScjlgx> list = spcyQyScjlgxService.list(new LambdaQueryWrapper<SpcyQyScjlgx>()
                .eq(SpcyQyScjlgx::getFwlmlid, fwlmlid)
                .eq(SpcyQyScjlgx::getFscjlid, fscjlid)
                .eq(SpcyQyScjlgx::getFwlkcid, wlkc.getId()));
        if (CollectionUtil.isNotEmpty(list)){
            throw new BusinessException("当前物料库存已经存在了！");
        }

        modifyWlkcNumber(false,wlkc.getId(),wlkc,scjlgx.getFwlsysl());

        scjlgx.setFwlkcid(wlkc.getId());
        spcyQyScjlgxService.save(scjlgx);

        String sm = "生产记录【使用】->产品批号["+scjl.getFcpph()+"]->产品名称["+scjl.getFspm()+"];";
        spcyQyWlkcjlService.addRckRecords(wlkc.getId(),SpcyCommonConstant.QY_RKJL_LX_CK,scjlgx.getFwlsysl(),sm);

        String log = "添加-企业生产记录物料信息：";
        log += "产品批号：["+scjl.getFcpph()+"];";
        log += "产品名称：["+scjl.getFspm()+"];";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(scjlgx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, scjl.getFqyid(), "添加-企业生产记录物料信息",SpcyConstant.LOGS_SYS_TYPE_XZ);

    }

    /**
     * 修改生产记录物料使用量
     */
    public void modifyScjlWl(String scjlwlid, Integer fwlsysl){
        if (StringUtils.isBlank(scjlwlid)){
            throw new BusinessException("数据参数为空！");
        }
        SpcyQyScjlgx scjlwl = spcyQyScjlgxService.getById(scjlwlid);
        if (scjlwl == null){
            throw new BusinessException("没有相匹配的生产记录物料数据！");
        }
        SpcyQyScjl scjl = spcyQyScjlService.getById(scjlwl.getFscjlid());
        if (scjl == null){
            throw new BusinessException("没有相匹配的生产记录数据！");
        }

        /**旧的数量 oldNum>num：入库/出库 */
        Integer oldNum = scjlwl.getFwlsysl();
        if (oldNum == fwlsysl){
            return;
        }

        modifyWlkcNumber(oldNum>fwlsysl?true:false,scjlwl.getFwlkcid(),null,oldNum>fwlsysl?oldNum-fwlsysl:fwlsysl-oldNum);
        scjlwl.setFwlsysl(fwlsysl);
        spcyQyScjlgxService.updateById(scjlwl);

        String sm = "生产记录【使用】->产品批号["+scjl.getFcpph()+"]->产品名称["+scjl.getFspm()+"];";
        spcyQyWlkcjlService.addRckRecords(scjlwl.getFwlkcid(),oldNum>fwlsysl?SpcyCommonConstant.QY_RKJL_LX_RK:SpcyCommonConstant.QY_RKJL_LX_CK, oldNum>fwlsysl?oldNum-fwlsysl:fwlsysl-oldNum, sm);
    }

    /**
     * 删除生产记录物料
     */
    public void deleteScjlwl(String scjlwlid){
        if (StringUtils.isBlank(scjlwlid)){
            throw new BusinessException("数据参数为空！");
        }
        this.deleteScjlwl(scjlwlid,null);
    }

    /**
     * 删除生产记录物料
     * @param scjlwlid 生产记录物料id
     * @param fscjlid 生产记录id
     */
    public void deleteScjlwl(String scjlwlid,String fscjlid){
        List<SpcyQyScjlgx> list = new ArrayList<>();
        if (StringUtils.isNotBlank(fscjlid)){
            list = spcyQyScjlgxService.list(new LambdaQueryWrapper<SpcyQyScjlgx>()
                    .eq(SpcyQyScjlgx::getFscjlid, fscjlid));
        }else {
            SpcyQyScjlgx scjlwl = spcyQyScjlgxService.getById(scjlwlid);
            if (scjlwl == null) {
                throw new BusinessException("没有相匹配的生产记录物料数据！");
            }
            list.add(scjlwl);
        }

        if (CollectionUtil.isEmpty(list)){
            return;
        }

        for (SpcyQyScjlgx scjlwl : list) {
            SpcyQyScjl scjl = spcyQyScjlService.getById(scjlwl.getFscjlid());
            if (scjl == null) {
                throw new BusinessException("没有相匹配的生产记录数据！");
            }

            Integer oldNum = scjlwl.getFwlsysl();
            modifyWlkcNumber(true, scjlwl.getFwlkcid(), null, oldNum);

            spcyQyScjlgxService.removeById(scjlwlid);

            String log = "删除-企业生产记录物料信息：";
            log += "产品批号：[" + scjl.getFcpph() + "];";
            log += "产品名称：[" + scjl.getFspm() + "];";
            log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(scjlwl));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, scjl.getFqyid(), "删除-企业生产记录物料信息", SpcyConstant.LOGS_SYS_TYPE_SC);
        }

    }

    /**
     * 查询生产记录使用车间列表
     */
    public List<SpcyQySccjjl> querySccjSyjlList(String fscjlid, String fsccjid){
        LambdaQueryWrapper<SpcyQySccjjl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(fscjlid), SpcyQySccjjl::getFscjlid, fscjlid);
        queryWrapper.eq(StringUtils.isNotBlank(fsccjid), SpcyQySccjjl::getFsccjid, fsccjid);
        queryWrapper.orderByDesc(SpcyQySccjjl::getCreateTime);
        List<SpcyQySccjjl> list = spcyQySccjjlService.list(queryWrapper);

        return list;
    }

    /**
     * 分页查询
     */
    public HttpResult<?> querySccjjlPageList(SpcyQySccjjl query, Integer pageNo, Integer pageSize) {
        Page<SpcyQySccjjl> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQySccjjl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFsccjid()),SpcyQySccjjl::getFsccjid,query.getFsccjid());
        queryWrapper.like(StringUtils.isNotBlank(query.getFgxhjmc()),SpcyQySccjjl::getFgxhjmc,query.getFgxhjmc());

        queryWrapper.orderByDesc(SpcyQySccjjl::getCreateTime);
        IPage<SpcyQySccjjl> pageList = spcyQySccjjlService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加生产记录使用车间
     */
    public HttpResult addScjlSycj(SpcyQySccjjl paramBo){
        if (StringUtils.isBlank(paramBo.getFscjlid())){
            throw new BusinessException("生产记录数据参数为空！");
        }
        if (StringUtils.isBlank(paramBo.getFsccjid())){
            throw new BusinessException("生产车间数据参数为空！");
        }
        if (paramBo.getFsykssj() == null){
            throw new BusinessException("请填写开始时间!");
        }
        if (paramBo.getFsyjssj() == null){
            throw new BusinessException("请填写结束时间!");
        }
        if (StringUtils.isBlank(paramBo.getFgxhjmc())){
            throw new BusinessException("请填写工序环节！");
        }

        SpcyQySccjjl sccjjl = null;

        List<SpcyQySccjjl> list = spcyQySccjjlService.list(new LambdaQueryWrapper<SpcyQySccjjl>()
                .eq(SpcyQySccjjl::getFscjlid, paramBo.getFscjlid())
                .eq(SpcyQySccjjl::getFsccjid, paramBo.getFsccjid()));
        if (CollectionUtil.isNotEmpty(list)){
            sccjjl = list.get(0);
        }

        if (sccjjl == null) {
            sccjjl = new SpcyQySccjjl();
            sccjjl.setId(GetUuIdUtils.ReplaceUuId());
            sccjjl.setFsccjid(paramBo.getFsccjid());
            sccjjl.setFscjlid(paramBo.getFscjlid());
            sccjjl.setFsykssj(paramBo.getFsykssj());
            sccjjl.setFsyjssj(paramBo.getFsyjssj());
            sccjjl.setFgxhjmc(paramBo.getFgxhjmc());
            spcyQySccjjlService.save(sccjjl);
        }else {
            sccjjl.setFsykssj(paramBo.getFsykssj());
            sccjjl.setFsyjssj(paramBo.getFsyjssj());
            sccjjl.setFgxhjmc(paramBo.getFgxhjmc());
            spcyQySccjjlService.updateById(sccjjl);
        }

        String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(sccjjl));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, sccjjl.getFscjlid(), "添加生产记录使用车间",SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(sccjjl);

        return result;
    }

    /**
     * 更新生产记录使用车间
     * @param buffer
     * @return
     */
    public HttpResult updateScjlSycj(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("数据参数为空！");
        }
        String id = buffer.get("id");
        SpcyQySccjjl updateBean = spcyQySccjjlService.getById(id);
        if (updateBean == null){
            return HttpResult.error("没有想匹配的车间记录数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);

        if (StringUtils.isBlank(updateBean.getFscjlid())){
            throw new BusinessException("生产记录数据参数为空！");
        }
        if (StringUtils.isBlank(updateBean.getFsccjid())){
            throw new BusinessException("生产车间数据参数为空！");
        }
        if (updateBean.getFsykssj() == null){
            throw new BusinessException("请填写开始时间!");
        }
        if (updateBean.getFsyjssj() == null){
            throw new BusinessException("请填写结束时间!");
        }
        if (StringUtils.isBlank(updateBean.getFgxhjmc())){
            throw new BusinessException("请填写工序环节！");
        }

        spcyQySccjjlService.updateById(updateBean);

        String operContent = "更新企业生产记录使用车间：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,updateBean.getFscjlid(),"更新企业生产记录使用车间",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除生产记录使用车间
     */
    public void deleteScjlSycj(String fsccjjlid){
        if (StringUtils.isBlank(fsccjjlid)){
            throw new BusinessException("车间记录数据参数为空！");
        }
        SpcyQySccjjl sccjjl = spcyQySccjjlService.getById(fsccjjlid);
        if (sccjjl == null){
            throw new BusinessException("没有想匹配的车间记录数据！");
        }
        boolean flag = spcyQySccjjlService.removeById(fsccjjlid);
        if (flag) {
            String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(sccjjl));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, sccjjl.getFscjlid(), "删除-删除生产记录使用车间", SpcyConstant.LOGS_SYS_TYPE_SC);
        }
    }

    /************************************[ 企业-关键指标 ]**************************************************************************/

    public HttpResult queryQyGjzbPageList(SpcyQyGjzb query,Integer pageNo,Integer pageSize){
        Page<SpcyQyGjzb> page = new Page<>(pageNo,pageSize);
        LambdaQueryWrapper<SpcyQyGjzb> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFpzid()), SpcyQyGjzb::getFpzid, query.getFpzid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()), SpcyQyGjzb::getFqyid, query.getFqyid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFxmmc()), SpcyQyGjzb::getFxmmc, query.getFxmmc());
        queryWrapper.orderByDesc(SpcyQyGjzb::getCreateTime);
        IPage<SpcyQyGjzb> list = spcyQyGjzbService.page(page,queryWrapper);

        return HttpResult.ok(list);
    }

    public HttpResult addGjzb(SpcyQyGjzb bean){

        bean.setId(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isBlank(bean.getFpzid())) {
            throw new BusinessException("检查参数数据为空！");
        }

        SpcyQyPzjbxx pzjbxx = spcyQyPzjbxxService.getById(bean.getFpzid());
        if (pzjbxx == null){
            throw new BusinessException("没有相匹配的品种数据！");
        }
        bean.setFqyid(pzjbxx.getFqyid());
        spcyQyGjzbService.save(bean);


        String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, bean.getFqyid(), "添加企业关键指标",SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(bean);

        return result;
    }

    public HttpResult updateGjzb(HashMap<String, String> buffer)throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("数据参数为空！");
        }
        String id = buffer.get("id");
        SpcyQyGjzb updateBean = spcyQyGjzbService.getById(id);
        if (updateBean == null){
            return HttpResult.error("没有想匹配的指标数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);
        spcyQyGjzbService.updateById(updateBean);

        String operContent = "更新企业关键指标：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,updateBean.getFqyid(),"更新企业关键指标",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public void deleteGjzb(String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("数据参数为空！");
        }
        SpcyQyGjzb bean = spcyQyGjzbService.getById(id);
        if (bean == null){
            throw new BusinessException("没有想匹配的指标数据！");
        }
        boolean flag = spcyQyGjzbService.removeById(bean);
        if (flag) {
            String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFqyid(), "删除-企业关键指标", SpcyConstant.LOGS_SYS_TYPE_SC);
        }
    }

    /************************************[ 企业-检验信息 ]**************************************************************************/

    public List<QyJyxxDto> queryQyJyxxList(QyJyxxDto query) {
        List<QyJyxxDto> jyxxList = spcyQyScjlMapper.findJyxxList(query);

        return jyxxList;
    }

    /** 添加 */
    public HttpResult addJyxx(SpcyQyJyxx jyxx){
        jyxx.setId(GetUuIdUtils.ReplaceUuId());

        if (StringUtils.isBlank(jyxx.getFscjlid())){
            throw new BusinessException("生产记录数据参数为空！");
        }
        SpcyQyScjl scjl = spcyQyScjlService.getById(jyxx.getFscjlid());
        if (scjl == null){
            throw new BusinessException("没有想匹配的生产记录数据！");
        }
        jyxx.setFqyid(scjl.getFqyid());

        spcyQyJyxxService.save(jyxx);

        String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(jyxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log, jyxx.getFqyid()+"/"+jyxx.getFscjlid(), "添加生产记录使用车间",SpcyConstant.LOGS_SYS_TYPE_XZ);


        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(jyxx);

        return result;
    }

    public HttpResult updateJyxx(HashMap<String, String> buffer)throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("数据参数为空！");
        }
        String id = buffer.get("id");
        SpcyQyJyxx updateBean = spcyQyJyxxService.getById(id);
        if (updateBean == null){
            return HttpResult.error("没有想匹配的检验记录数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);
        spcyQyJyxxService.updateById(updateBean);

        String operContent = "更新企业检验信息：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,updateBean.getFqyid()+"/"+updateBean.getFscjlid(),"更新企业检验信息",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public void deleteJyxx(String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("数据参数为空！");
        }
        SpcyQyJyxx bean = spcyQyJyxxService.getById(id);
        if (bean == null){
            throw new BusinessException("没有想匹配的检验记录数据！");
        }
        boolean flag = spcyQyJyxxService.removeById(bean);
        if (flag) {
            this.deleteJyxmByJyId(id);
            this.deleteInfoFileByFpid(id);

            String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFqyid()+"/"+bean.getFscjlid(), "删除-删除企业检验信息", SpcyConstant.LOGS_SYS_TYPE_SC);
        }
    }

    /************************************[ 企业-检验项目 ]**************************************************************************/

    public List<SpcyQyJcxm> queryQyJyxmList(SpcyQyJcxm query){
        LambdaQueryWrapper<SpcyQyJcxm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFjyid()), SpcyQyJcxm::getFjyid, query.getFjyid());
        queryWrapper.orderByDesc(SpcyQyJcxm::getCreateTime);
        List<SpcyQyJcxm> list = spcyQyJcxmService.list(queryWrapper);
        return list;
    }

    public HttpResult addJyxm(SpcyQyJcxm bean){

        bean.setId(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isBlank(bean.getFjyid())){
            throw new BusinessException("检查参数数据为空！");
        }

        List<SpcyQyJcxm> orderList = this.queryQyJyxmList(new SpcyQyJcxm(bean.getFjyid()));
        bean.setFxmxh(orderList.size()+1);

        spcyQyJcxmService.save(bean);

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(bean);

        return result;
    }

    public HttpResult updateJyxm(HashMap<String, String> buffer)throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("数据参数为空！");
        }
        String id = buffer.get("id");
        SpcyQyJcxm updateBean = spcyQyJcxmService.getById(id);
        if (updateBean == null){
            return HttpResult.error("没有想匹配的检验项目数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);
        spcyQyJcxmService.updateById(updateBean);

        String operContent = "更新企业检验项目：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,updateBean.getFjyid(),"更新企业检验项目",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public void deleteJyxm(String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("数据参数为空！");
        }
        SpcyQyJcxm bean = spcyQyJcxmService.getById(id);
        if (bean == null){
            throw new BusinessException("没有想匹配的检验项目数据！");
        }
        boolean flag = spcyQyJcxmService.removeById(bean);
        if (flag) {
            String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFjyid(), "删除-删除企业检验项目", SpcyConstant.LOGS_SYS_TYPE_SC);
        }
    }

    public void deleteJyxmByJyId(String fjyid){
        if (StringUtils.isBlank(fjyid)){
            return;
        }

        List<SpcyQyJcxm> list = spcyQyJcxmService.list(new LambdaQueryWrapper<SpcyQyJcxm>()
                .eq(SpcyQyJcxm::getFjyid, fjyid));

        if (CollectionUtil.isEmpty(list)){
            return;
        }

        for (SpcyQyJcxm bean : list){
            boolean flag = spcyQyJcxmService.removeById(bean);
            if (flag) {
                String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
                spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFjyid(), "删除-删除企业检验项目", SpcyConstant.LOGS_SYS_TYPE_SC);
            }
        }
    }

    /************************************[ 企业-企业委托 ]**************************************************************************/

    public HttpResult queryQyWtxxPageList(SpcyQyQywtxx query,Integer pageNo,Integer pageSize){
        if (StringUtils.isBlank(query.getFqyid())){
            throw new BusinessException("企业参数为空！");
        }
        Page<SpcyQyQywtxx> page = new Page<>(pageNo,pageSize);
        LambdaQueryWrapper<SpcyQyQywtxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()), SpcyQyQywtxx::getFqyid, query.getFqyid());
        queryWrapper.like(StringUtils.isNotBlank(query.getFgzdw()), SpcyQyQywtxx::getFgzdw, query.getFgzdw());
        queryWrapper.like(StringUtils.isNotBlank(query.getFwtdw()), SpcyQyQywtxx::getFwtdw, query.getFwtdw());
        queryWrapper.like(StringUtils.isNotBlank(query.getFwtrxm()), SpcyQyQywtxx::getFwtrxm, query.getFwtrxm());
        queryWrapper.like(StringUtils.isNotBlank(query.getFswtrxm()), SpcyQyQywtxx::getFswtrxm, query.getFswtrxm());
        queryWrapper.orderByDesc(SpcyQyQywtxx::getCreateTime);
        Page<SpcyQyQywtxx> pageList = spcyQyQywtxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    public HttpResult addQywtxx(SpcyQyQywtxx bean){

        bean.setId(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isBlank(bean.getFqyid())){
            throw new BusinessException("企业参数数据为空！");
        }

        spcyQyQywtxxService.save(bean);

        String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFqyid(), "添加-企业委托项目", SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(bean);

        return result;
    }

    public HttpResult updateQywtxx(HashMap<String, String> buffer)throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("数据参数为空！");
        }
        String id = buffer.get("id");
        SpcyQyQywtxx updateBean = spcyQyQywtxxService.getById(id);
        if (updateBean == null){
            return HttpResult.error("没有想匹配的委托数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);
        spcyQyQywtxxService.updateById(updateBean);

        String operContent = "更新企业委托信息：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,updateBean.getFqyid(),"更新企业委托信息",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public void deleteQyWtxx(String ids){
        if (StringUtils.isBlank(ids)){
            throw new BusinessException("数据参数为空！");
        }
        List<String> idList = StringPatternUtils.getListByIds(ids);
        List<SpcyQyQywtxx> wtList = spcyQyQywtxxService.listByIds(idList);
        if (CollectionUtil.isEmpty(wtList)){
            throw new BusinessException("没有相匹配的数据！");
        }
        for (SpcyQyQywtxx bean : wtList) {
            /*SpcyQyQywtxx bean = spcyQyQywtxxService.getById(id);
            if (bean == null) {
                throw new BusinessException("没有想匹配的委托数据！");
            }*/
            boolean flag = spcyQyQywtxxService.removeById(bean.getId());
            if (flag) {
                String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
                spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFqyid(), "删除-删除企业委托项目", SpcyConstant.LOGS_SYS_TYPE_SC);
            }
        }
    }

    /************************************[ 企业-设备信息 ]**************************************************************************/

    public HttpResult queryQySbxxPageList(SpcyQySbxx query,String gjz, Integer pageNo,Integer pageSize){
        if (StringUtils.isBlank(query.getFqyid())){
            throw new BusinessException("企业参数为空！");
        }
        Page<SpcyQySbxx> page = new Page<>(pageNo,pageSize);
        LambdaQueryWrapper<SpcyQySbxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFqyid()), SpcyQySbxx::getFqyid, query.getFqyid());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFsblx()), SpcyQySbxx::getFsblx, query.getFsblx());
        queryWrapper.like(StringUtils.isNotBlank(query.getFsbmc()), SpcyQySbxx::getFsbmc, query.getFsbmc());
        queryWrapper.like(StringUtils.isNotBlank(query.getFccbh()), SpcyQySbxx::getFccbh, query.getFccbh());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFsbzt()), SpcyQySbxx::getFsbzt, query.getFsbzt());

        if (StringUtils.isNotBlank(gjz)){
            queryWrapper.and(q-> q.like(SpcyQySbxx::getFccbh, gjz)
                    .or()
                    .like(SpcyQySbxx::getFsbmc, gjz)
            );
        }

        queryWrapper.orderByAsc(SpcyQySbxx::getCreateTime);
        Page<SpcyQySbxx> pageList = spcyQySbxxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    public HttpResult addQySbxx(SpcyQySbxx bean){

        bean.setId(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isBlank(bean.getFqyid())){
            throw new BusinessException("企业参数数据为空！");
        }

        spcyQySbxxService.save(bean);

        String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFqyid(), "添加-企业设备信息", SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(bean);

        return result;
    }

    public HttpResult updateQySbxx(HashMap<String, String> buffer)throws InvocationTargetException, IllegalAccessException{
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("数据参数为空！");
        }
        String id = buffer.get("id");
        SpcyQySbxx updateBean = spcyQySbxxService.getById(id);
        if (updateBean == null){
            return HttpResult.error("没有想匹配的设备数据！");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(updateBean);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);
        spcyQySbxxService.updateById(updateBean);

        String operContent = "更新企业设备信息：";
        operContent += LogUtils.BeanModifyMsg(updateBean,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,updateBean.getFqyid(),"更新企业企业设备信息",SpcyConstant.LOGS_SYS_TYPE_XG);

        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public void deleteQySbxx(String ids){
        if (StringUtils.isBlank(ids)){
            throw new BusinessException("数据参数为空！");
        }

        List<String> idList = StringPatternUtils.getListByIds(ids);
        List<SpcyQySbxx> wtList = spcyQySbxxService.listByIds(idList);
        if (CollectionUtil.isEmpty(wtList)){
            throw new BusinessException("没有相匹配的数据！");
        }
        for (SpcyQySbxx bean : wtList) {

            boolean flag = spcyQySbxxService.removeById(bean.getId());
            if (flag) {
                String log = LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(bean));
                spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, log, bean.getFqyid(), "删除-删除企业委托项目", SpcyConstant.LOGS_SYS_TYPE_SC);
            }
        }
    }

    /************************************[ 企业-预警信息 ]**************************************************************************/

    /**
     * 证件预警信息
     * @param onlyCurrentUser true:当前登录企业
     */
    public HttpResult queryZjyjPageList(String fqyid, String onlyCurrentUser){
        List<QyZjyjxxParamBo> ygqList = new ArrayList<>();
        List<QyZjyjxxParamBo> jjgqList = new ArrayList<>();
        List<QyZjyjxxParamBo> ysyxList = new ArrayList<>();
        List<QyZjyjxxParamBo> cqyxList = new ArrayList<>();

        QyZjyjxxParamBo paramBo = new QyZjyjxxParamBo();
        String qyid = null;

        if (StringUtils.isNotBlank(fqyid)){
            qyid = fqyid;
        }else {
            if (StringUtils.isNotBlank(onlyCurrentUser) && onlyCurrentUser.equals("true")){
                qyid = getCurrentQy();
                if (StringUtils.isBlank(qyid)){
                    qyid = "0";
                }
            }
        }
        paramBo.setFqyid(qyid);
        List<QyZjyjxxParamBo> zjxxList = this.getZjxxList(paramBo);
        if (CollectionUtils.isNotEmpty(zjxxList)){

            ygqList = zjxxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ))
                    .collect(Collectors.toList());

            jjgqList = zjxxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ))
                    .collect(Collectors.toList());

            ysyxList = zjxxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX))
                    .collect(Collectors.toList());

            cqyxList = zjxxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX))
                    .collect(Collectors.toList());

        }

        Map resultMap = new HashMap();
        resultMap.put("ygqSize", ygqList.size()); // 已过期
        resultMap.put("ygqList", ygqList); // 已过期

        resultMap.put("jjgqSize", jjgqList.size()); // 即将过期
        resultMap.put("jjgqList", jjgqList); // 即将过期

        resultMap.put("ysyxSize", ysyxList.size()); // 以上有效
        resultMap.put("ysyxList", ysyxList); // 以上有效

        resultMap.put("cqyxSize", cqyxList.size()); // 长期有效
        resultMap.put("cqyxList", cqyxList); // 长期有效

        return HttpResult.ok(resultMap);
    }

    /** 物料审计预警信息
     * @param onlyCurrentUser true:当前登录企业
     * */
    public HttpResult queryWlsjyjPageList(String fqyid, String onlyCurrentUser){

        List<QyYlgyssjYjxxParamBo> ygqList = new ArrayList<>();
        List<QyYlgyssjYjxxParamBo> jjgqList = new ArrayList<>();
        List<QyYlgyssjYjxxParamBo> ysyxList = new ArrayList<>();
        List<QyYlgyssjYjxxParamBo> cqyxList = new ArrayList<>();

        QyYlgyssjYjxxParamBo paramBo = new QyYlgyssjYjxxParamBo();
        String qyid = null;

        if (StringUtils.isNotBlank(fqyid)){
            qyid = fqyid;
        }else {
            if (StringUtils.isNotBlank(onlyCurrentUser) && onlyCurrentUser.equals("true")){
                qyid = getCurrentQy();
                if (StringUtils.isBlank(qyid)){
                    qyid = "0";
                }
            }
        }
        paramBo.setFqyid(qyid);
        List<QyYlgyssjYjxxParamBo> xxList = this.getWlxxList(paramBo);
        if (CollectionUtils.isNotEmpty(xxList)){

            ygqList = xxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YGQ))
                    .collect(Collectors.toList());

            jjgqList = xxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_JJGQ))
                    .collect(Collectors.toList());

            ysyxList = xxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_YSYX))
                    .collect(Collectors.toList());

            cqyxList = xxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getSfgq()) && f.getSfgq().equals(SpcyCommonConstant.QY_ZJXX_ZJYXQ_CQYX))
                    .collect(Collectors.toList());

        }

        Map resultMap = new HashMap();
        resultMap.put("ygqSize", ygqList.size()); // 已过期
        resultMap.put("ygqList", ygqList); // 已过期

        resultMap.put("jjgqSize", jjgqList.size()); // 即将过期
        resultMap.put("jjgqList", jjgqList); // 即将过期

        resultMap.put("ysyxSize", ysyxList.size()); // 以上有效
        resultMap.put("ysyxList", ysyxList); // 以上有效

        resultMap.put("cqyxSize", cqyxList.size()); // 长期有效
        resultMap.put("cqyxList", cqyxList); // 长期有效

        return HttpResult.ok(resultMap);
    }

    /** 物料平衡预警信息
     * @param onlyCurrentUser true:当前登录企业
     * */
    public HttpResult queryWlphyjPageList(String fqyid, String onlyCurrentUser){

        String qyid = null;

        if (StringUtils.isNotBlank(fqyid)){
            qyid = fqyid;
        }else {
            if (StringUtils.isNotBlank(onlyCurrentUser) && onlyCurrentUser.equals("true")){
                qyid = getCurrentQy();
                if (StringUtils.isBlank(qyid)){
                    qyid = "0";
                }
            }
        }

        WlphYjDto xy = new WlphYjDto();
        xy.setSfxyyjz("是");
        xy.setFqyid(qyid);
        List<WlphYjDto> xyList = spcyQyWlmlMapper.findWlphYjList(xy);

        WlphYjDto dy = new WlphYjDto();
        dy.setSfdyyjz("是");
        dy.setDyyjzcz(10);
        dy.setFqyid(qyid);
        List<WlphYjDto> dyList = spcyQyWlmlMapper.findWlphYjList(dy);

        WlphYjDto empty = new WlphYjDto();
        empty.setYjzsfwk("是");
        empty.setFqyid(qyid);
        List<WlphYjDto> emptyList = spcyQyWlmlMapper.findWlphYjList(empty);

        Map result = new HashMap();
        // 库存值小于预警值
        result.put("xySize", xyList.size());
        result.put("xyList", xyList);

        // 库存值大于预警值
        result.put("dySize", dyList.size());
        result.put("dyList", dyList);

        // 库存值等于0
        result.put("emptySize", emptyList.size());
        result.put("emptyList", emptyList);
        return HttpResult.ok(result);
    }

    /**
     * 生产环境预警
     * @param onlyCurrentUser true: 当前登录企业
     */
    public HttpResult querySchjYjPageList(String fqyid, String onlyCurrentUser){
        String qyid = null;

        if (StringUtils.isNotBlank(fqyid)){
            qyid = fqyid;
        }else {
            if (StringUtils.isNotBlank(onlyCurrentUser) && onlyCurrentUser.equals("true")){
                qyid = getCurrentQy();
                if (StringUtils.isBlank(qyid)){
                    qyid = "0";
                }
            }
        }

        // 所有预警值
        List<QySchjYjParamBo> allList = spcyQySccjMapper.findSchjYjList(qyid);

        List<QySchjYjParamBo> yjList = new ArrayList<>();
        List<QySchjYjParamBo> wyyjzList = new ArrayList<>();
        List<QySchjYjParamBo> wycbzList = new ArrayList<>();
        List<QySchjYjParamBo> cbList = new ArrayList<>();

        if (CollectionUtil.isNotEmpty(allList)){
            yjList = allList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getYjzt()) && f.getYjzt().equals(SpcyCommonConstant.QY_SCCJ_SCHJ_XYYJX))
                    .collect(Collectors.toList());

            wyyjzList = allList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getYjzt()) && f.getYjzt().equals(SpcyCommonConstant.QY_SCCJ_SCHJ_DeYuYJX))
                    .collect(Collectors.toList());

            wycbzList = allList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getYjzt()) && f.getYjzt().equals(SpcyCommonConstant.QY_SCCJ_SCHJ_DeYuCBX))
                    .collect(Collectors.toList());

            cbList = allList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getYjzt()) && f.getYjzt().equals(SpcyCommonConstant.QY_SCCJ_SCHJ_DaYuCBX))
                    .collect(Collectors.toList());
        }
        Map resultMap = new HashMap();
        resultMap.put("yjSize", yjList.size()); // 低于预警
        resultMap.put("yjList", yjList);

        resultMap.put("wyyjzSize", wyyjzList.size()); // 等于预警
        resultMap.put("wyyjzList", wyyjzList);

        resultMap.put("wycbzSize", wycbzList.size()); // 等于超标
        resultMap.put("wycbzList", wycbzList);

        resultMap.put("cbSize", cbList.size()); // 大于超标
        resultMap.put("cbList", cbList);
        return HttpResult.ok(resultMap);
    }

    /**
     * 车间环境浓度预警
     * @param id 车间id
     * @param dayDate 预警日期（yyyy-mm-dd）
     */
    public HttpResult queryCjYjxx(String id,String dayDate){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("操作失败，参数为空！");
        }

        SpcyQySccj sccj = spcyQySccjService.getById(id);
        if (sccj == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        List<Map> resultList = new ArrayList<>();

        LambdaQueryWrapper<SpcyQySchj> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(id), SpcyQySchj::getFsccjid, id);
        if (StringUtils.isNotBlank(dayDate)){
            queryWrapper.apply("to_char(fdjsj,'yyyy-mm-dd') = {0}", dayDate);
        }
        queryWrapper.orderByAsc(SpcyQySchj::getFdjsj);
        queryWrapper.orderByAsc(SpcyQySchj::getCreateTime);
        List<SpcyQySchj> list = spcyQySchjService.list(queryWrapper);

        Map parMap = null;
        for (SpcyQySchj bean : list){
            parMap = new HashMap();

            Integer fyjz = Optional.ofNullable(sccj.getFyjz()).orElseGet(()->0);
            Integer fcbz = Optional.ofNullable(sccj.getFcbz()).orElseGet(()->0);

            parMap.put("fwswnd", Optional.ofNullable(bean.getFwswnd()).orElseGet(()->0));
            parMap.put("fdjsj", bean.getFdjsj());
            parMap.put("fyjz", fyjz);
            parMap.put("fcbz", fcbz);
            parMap.put("fcjbh", sccj.getFcjbh());
            parMap.put("fcjmc", sccj.getFcjmc());
            parMap.put("fjllx", bean.getFjllx());

            String dw = "";
            if (StringUtils.isBlank(bean.getFjllx())){
                dw = "cfu";
            }else if (bean.getFjllx().equals("浮游菌")){
                dw = "cfu/4h";
            }else if (bean.getFjllx().equals("沉降菌")){
                dw = "cfu/m3";
            }else {

            }
            parMap.put("dw", dw);

            BigDecimal yjzBd = new BigDecimal(String.valueOf(fyjz));
            BigDecimal cbzBd = new BigDecimal(String.valueOf(fcbz));
            BigDecimal totalBd = yjzBd.add(cbzBd);
            BigDecimal pjz = totalBd.divide(new BigDecimal("2"), 0, BigDecimal.ROUND_DOWN);
            parMap.put("pjz", pjz);

            resultList.add(parMap);
        }
        return HttpResult.ok(resultList);
    }

    /**
     * 关键指标预警
     * @param onlyCurrentUser true: 当前登录企业
     */
    public HttpResult queryGjzbYjPageList(String fqyid, String onlyCurrentUser){
        String qyid = null;

        if (StringUtils.isNotBlank(fqyid)){
            qyid = fqyid;
        }else {
            if (StringUtils.isNotBlank(onlyCurrentUser) && onlyCurrentUser.equals("true")){
                qyid = getCurrentQy();
                if (StringUtils.isBlank(qyid)){
                    qyid = "0";
                }
            }
        }

        List<QyGjzbYjParamBo> list = spcyQyScjlMapper.findGjzbYjList(qyid);

        List<QyGjzbYjParamBo> yjList = new ArrayList<>();
        List<QyGjzbYjParamBo> cbList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(list)){
            yjList = list.stream()
                    .filter(f->StringUtils.isNotBlank(f.getYjdj()) && f.getYjdj().equals(SpcyCommonConstant.QY_GJZB_YJ))
                    .collect(Collectors.toList());

            cbList = list.stream()
                    .filter(f->StringUtils.isNotBlank(f.getYjdj()) && f.getYjdj().equals(SpcyCommonConstant.QY_GJZB_CB))
                    .collect(Collectors.toList());
        }

        Map result = new HashMap();
        result.put("yjSize", yjList.size());
        result.put("yjList", yjList);

        result.put("cbSize", cbList.size());
        result.put("cbList", cbList);
        return HttpResult.ok(result);
    }

    /**
     * 根据检验项目-获取所有关键指标
     */
    public HttpResult queryGjzbListByJyxx(String fjyid){
        if (StringUtils.isBlank(fjyid)){
            throw new BusinessException("检验参数为空！");
        }
        List<QyGjzbListStatDto> list = spcyQyScjlMapper.findAllGjzbAllListByJyid(fjyid);

        return HttpResult.ok(list);
    }

    /**
     * 根据检验项目-查询关键指标预警信息
     */
    public HttpResult queryGjzbYjByJyxx(String fjyid, String fxmmc){
        if (StringUtils.isBlank(fjyid) || StringUtils.isBlank(fxmmc)){
            return HttpResult.ok(new ArrayList(1));
        }

        List<QyGjzbStatDto> list = spcyQyScjlMapper.findGjzbByJyid(fjyid, fxmmc);
        /*List<QyGjzbStatDto> list = new ArrayList<>();
        QyGjzbStatDto dto1 = new QyGjzbStatDto();
        dto1.setFbgrq("2023-12-07");
        dto1.setFjysj("0.08%");
        list.add(dto1);

        QyGjzbStatDto dto2 = new QyGjzbStatDto();
        dto2.setFbgrq("2023-12-08");
        dto2.setFjysj("0.082%");
        list.add(dto2);

        QyGjzbStatDto dto3 = new QyGjzbStatDto();
        dto3.setFbgrq("2023-12-09");
        dto3.setFjysj("0.083%");
        list.add(dto3);

        QyGjzbStatDto dto4 = new QyGjzbStatDto();
        dto4.setFbgrq("2023-12-10");
        dto4.setFjysj("0.084%");
        list.add(dto4);

        QyGjzbStatDto dto5 = new QyGjzbStatDto();
        dto5.setFbgrq("2023-12-11");
        dto5.setFjysj("0.085%");
        list.add(dto5);*/

        return HttpResult.ok(list);
    }

    /************************************[ 企业-违法违纪 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryQyWfwjjlPageList(SpcyQyWfwjjl wfwjjl, Integer pageNo, Integer pageSize) {
        Page<SpcyQyWfwjjl> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyWfwjjl> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(wfwjjl.getFqyid()),SpcyQyWfwjjl::getFqyid,wfwjjl.getFqyid());
        queryWrapper.like(StringUtils.isNotEmpty(wfwjjl.getFwfnr()),SpcyQyWfwjjl::getFwfnr,wfwjjl.getFwfnr());
        queryWrapper.like(StringUtils.isNotEmpty(wfwjjl.getFbz()),SpcyQyWfwjjl::getFbz,wfwjjl.getFbz());

        queryWrapper.orderByDesc(SpcyQyWfwjjl::getCreateTime);
        IPage<SpcyQyWfwjjl> pageList = spcyQyWfwjjlService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addQyWfwjjl(SpcyQyWfwjjl wfwjjl, boolean onlyCurrentUser){
        wfwjjl.setId(GetUuIdUtils.ReplaceUuId());
        if (onlyCurrentUser){
            wfwjjl.setFqyid(this.getCurrentQy());
        }else {
            if (StringUtils.isBlank(wfwjjl.getFqyid())){
                return HttpResult.error("企业参数不能为空, 请联系管理员");
            }
        }
        wfwjjl.setFtxrq(new Date());
        spcyQyWfwjjlService.save(wfwjjl);

        this.updateQyWfcs(wfwjjl.getFqyid(),true); // 企业违法次数

        String log = "添加-企业-违法违纪记录：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(wfwjjl));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,wfwjjl.getFqyid(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(wfwjjl);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateWfwjjl(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String wjmlId = buffer.get("id");
        SpcyQyWfwjjl Update = spcyQyWfwjjlService.getById(wjmlId);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyWfwjjlService.updateById(Update);

        String operContent = "企业-违法违纪-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,wjmlId,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 清空
     */
    public HttpResult emptyWfjl(String qyid){
        if (StringUtils.isEmpty(qyid)){
            return HttpResult.error("企业参数不能为空");
        }

        List<SpcyQyWfwjjl> wfList = spcyQyWfwjjlService.list(new LambdaQueryWrapper<SpcyQyWfwjjl>()
                .eq(SpcyQyWfwjjl::getFqyid, qyid));
        if (CollectionUtils.isNotEmpty(wfList)) {
            for (SpcyQyWfwjjl wfwjjl : wfList) {
                this.deleteWfwjjl(wfwjjl.getId());
            }
        }
        return HttpResult.ok("清空违法记录成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteWfwjjl(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyWfwjjl> sqsxWjmlList = spcyQyWfwjjlService.listByIds(idsList);
        if (CollectionUtils.isEmpty(sqsxWjmlList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyWfwjjl wjml : sqsxWjmlList){
            String id = wjml.getId();
            spcyQyWfwjjlService.removeById(id);
            this.updateQyWfcs(wjml.getFqyid(),false); // 企业违法次数

            operContent = "删除-企业违法违纪信息：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(wjml);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 添加和减少 企业违法次数
     * @param fyqid 企业id
     * @param isAdd true：增加，false：减少
     */
    public void updateQyWfcs(String fyqid,boolean isAdd){
        if (StringUtils.isBlank(fyqid)){
            return;
        }
        SpcyQyJbxx qy = spcyQyJbxxService.getById(fyqid);
        if (qy == null){
            return;
        }
        int count = qy.getFwfcs();
        if (isAdd){
            count++;
        }else {
            if (count>0) {
                count--;
            }
        }
        qy.setFwfcs(count);
        spcyQyJbxxService.updateById(qy);
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryWfwjjlById(String id) {
        SpcyQyJcxx jcxx = spcyQyJcxxService.getById(id);
        return HttpResult.ok(jcxx);
    }

    /************************************[ 企业-人员类型 ]**************************************************************************/

    /**
     * 分页查询
     */
    public HttpResult<?> queryRylxPageList(SpcyQyRylx rylx, Integer pageNo, Integer pageSize) {
        Page<SpcyQyRylx> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<SpcyQyRylx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(rylx.getFrylx()),SpcyQyRylx::getFrylx,rylx.getFrylx());

        queryWrapper.orderByDesc(SpcyQyRylx::getCreateTime);
        queryWrapper.orderByAsc(SpcyQyRylx::getForder);
        IPage<SpcyQyRylx> pageList = spcyQyRylxService.page(page, queryWrapper);
        return HttpResult.ok(pageList);
    }

    // 获取全部-人员类型
    public HttpResult<?> queryAllRylxList(){
        List<String> typeList = new ArrayList<>();
        List<SpcyQyRylx> list = spcyQyRylxService.list(new LambdaQueryWrapper<SpcyQyRylx>()
                .orderByAsc(SpcyQyRylx::getForder));
        if (CollectionUtils.isNotEmpty(list)){
            typeList = list.stream().map(SpcyQyRylx::getFrylx).collect(Collectors.toList());
        }
        return HttpResult.ok(typeList);
    }

    /**
     * 添加
     * @param onlyCurrentUser false：不查询企业(默认)；true：查询当前企业
     */
    public HttpResult addRylx(SpcyQyRylx jbxx, boolean onlyCurrentUser){
        if (StringUtils.isBlank(jbxx.getFrylx())){
            return HttpResult.error("人员类型参数为空");
        }
        jbxx.setId(GetUuIdUtils.ReplaceUuId());

        // 获取序号
        List<SpcyQyRylx> list = spcyQyRylxService.list();
        int index = list.size() + 1;
        jbxx.setForder(index);

        spcyQyRylxService.save(jbxx);

        String log = "添加-企业-人员类型：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(jbxx));
        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,jbxx.getId(), SpcyConstant.LOGS_SYS_TYPE_XZ,SpcyConstant.LOGS_SYS_TYPE_XZ);

        HttpResult httpResult = new HttpResult(true);
        httpResult.setResult(jbxx);
        httpResult.setMessage("保存成功");
        return httpResult;
    }

    /**
     * 更新
     * @param buffer
     * @return
     */
    public HttpResult updateRylx(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isEmpty(buffer.get("id"))){
            return HttpResult.error("信息id不能为空");
        }
        String id = buffer.get("id");
        SpcyQyRylx Update = spcyQyRylxService.getById(id);
        if (Update == null){
            return HttpResult.error("当前基本信息数据不存在，请重试");
        }
        Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(Update);
        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(Update, buffer);
        spcyQyRylxService.updateById(Update);

        String operContent = "企业-人员类型-修改：";
        operContent += LogUtils.BeanModifyMsg(Update,oldMap);

        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_XG,SpcyConstant.LOGS_SYS_TYPE_XG);
        return HttpResult.ok("保存成功");
    }

    /**
     * 删除
     */
    public HttpResult deleteRylx(String ids){
        if (StringUtils.isEmpty(ids)){
            return HttpResult.error("ids参数不能为空");
        }
        List<String> idsList = Arrays.asList(ids.split(",|，"));
        List<SpcyQyRylx> rylxList = spcyQyRylxService.listByIds(idsList);
        if (CollectionUtils.isEmpty(rylxList)){
            return HttpResult.error("数据不存在，请重试");
        }
        String operContent = "";
        for (SpcyQyRylx rylx : rylxList){
            String id = rylx.getId();
            spcyQyRylxService.removeById(id);

            operContent = "删除-企业人员类型：";
            Map<String, Object> oldMap = ObjectToMapUtils.objectToMap(rylx);
            operContent += LogUtils.MapToStringMethod(oldMap);
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,operContent,id,SpcyConstant.LOGS_SYS_TYPE_SC,SpcyConstant.LOGS_SYS_TYPE_SC);
            operContent = "";
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 通过id查询
     * @return
     */
    public HttpResult<?> queryRylxById(String id) {
        SpcyQyRylx jbxx = spcyQyRylxService.getById(id);
        return HttpResult.ok(jbxx);
    }

    /************************************[ 企业-文件记录 ]**************************************************************************/

    /**
     * 上传文件
     * @param uploadFile 文件
     * @param id  业务id
     * @param spcyQyWjjl
     * @return
     */
    public HttpResult uploadMoreTypeFile(MultipartFile[] uploadFile, String id,
                                            SpcyQyWjjl spcyQyWjjl){

        if (StringUtils.isEmpty(id)){
            return HttpResult.error("主要业务id不能为空");
        }

        if (uploadFile == null || uploadFile.length == 0) {
            return HttpResult.error("上传失败,请先选择文件");
        }

        for (MultipartFile file : uploadFile) {

            String originalFilename = file.getOriginalFilename();
            // 文件类型
            String wjlx = originalFilename.substring(originalFilename.lastIndexOf("."));

            // 文件名
            String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));

            if (StringUtils.isBlank(spcyQyWjjl.getFwjxsmc())) {
                spcyQyWjjl.setFwjxsmc(fileName);
            }

            String sjmc = GetUuIdUtils.NotReplaceUuId();
            String wjccmc = sjmc + wjlx;
            String nowDay = DateConversionUtils.DateToMonthTwo(new Date()); // 获取当前日期 yyyy-MM-dd
            String newDir = SpcyConstant.QY_Wjjl_File_Base_Url + "/" + nowDay;

            localFileUploadUtils.uploadZdyFile(file, wjccmc, newDir,businessConstant.isEnableQywjMinio); // 上传文件

            String Id = GetUuIdUtils.NotReplaceUuId();
            spcyQyWjjl.setId(Id);
            spcyQyWjjl.setFpid(id);
            spcyQyWjjl.setFwjlx(wjlx);
            spcyQyWjjl.setFwjccmc(wjccmc);
            String cflj = "/" + newDir + "/" + wjccmc;
            spcyQyWjjl.setFcflj(cflj);

            boolean save = spcyQyWjjlService.save(spcyQyWjjl);
            if (save) {
                String czContent = "上传企业文件: ";
                czContent += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(spcyQyWjjl));
                spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, czContent, id, SpcyConstant.LOGS_SYS_TYPE_BC, SpcyConstant.LOGS_SYS_TYPE_BC);
            }
        }

        return HttpResult.ok("上传成功");
    }

    public SpcyQyWjjl uploadCommonParts(Collection<Part> parts, String wjid) {
        return uploadCommonParts(parts, wjid, "", "", "", "", "");
    }
    public SpcyQyWjjl uploadCommonParts(Collection<Part> parts, String fpid, String type, String fwjxsmc, String fwjlx5, String fwjlx6) {
        return uploadCommonParts(parts, "", fpid, type, fwjxsmc, fwjlx5, fwjlx6);
    }
    public SpcyQyWjjl uploadCommonParts(Collection<Part> parts, String wjid, String fpid, String type, String fwjxsmc, String fwjlx5, String fwjlx6) {
        List<File> fileList = new ArrayList<>(parts.size());
        for (Part part : parts) {
            try {
                String fileName = Paths.get(part.getSubmittedFileName()).getFileName().toString();
                String wjHz = Util.getWjHz(fileName);

                File file = localFileUploadUtils.uploadDempFile(part, GetUuIdUtils.NotReplaceUuId() + wjHz);
                if (file != null) {
                    fileList.add(file);
                }
            }catch (Exception e){
                continue;
            }
        }

        return this.uploadCommonFile(fileList, wjid, fpid, type, fwjxsmc, fwjlx5, fwjlx6);
    }

    public SpcyQyWjjl uploadCommonFile(List<File> fileList, String wjid, String fpid, String type, String fwjxsmc, String fwjlx5, String fwjlx6){
        if (StringUtils.isNotBlank(wjid)){

            SpcyQyWjjl wj = spcyQyWjjlService.getById(wjid);
            if (wj == null){
                return null;
            }

            if (CollectionUtil.isNotEmpty(fileList)){

                String originalFilename = fileList.get(0).getName();
                // 文件类型
                String wjlx = originalFilename.substring(originalFilename.lastIndexOf("."));

                // 文件名
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));

                if (StringUtils.isBlank(wj.getFwjxsmc())) {
                    wj.setFwjxsmc(fileName);
                }
                String sjmc = GetUuIdUtils.ReplaceUuId();
                String wjccmc = sjmc + wjlx;
                String newDir = SpcyConstant.QY_Wjjl_File_Base_Url + "/" + DateConversionUtils.DateToMonthTwo(new Date());
                String cflj = "/" + newDir + "/" + wjccmc;
                boolean uploadFlag = spcyMinioUtils.putFlagFile(cflj, fileList.get(0), wjlx);
                if (uploadFlag) {
                    if (StringUtils.isNotBlank(wj.getFcflj())) {
                        localFileUploadUtils.deleteLocalFileUrlByZdy(wj.getFcflj(), businessConstant.isEnableQywjMinio);
                    }

                    /*if (StringUtils.isNotBlank(fwjxsmc)){
                        wj.setFwjxsmc(fwjxsmc);
                    }
                    if (StringUtils.isNotBlank(fwjlx5)){
                        wj.setFwjlx5(fwjlx5);
                    }
                    if (StringUtils.isNotBlank(fwjlx6)){
                        wj.setFwjlx6(fwjlx6);
                    }*/
                    wj.setFwjxsmc(sjmc);
                    wj.setFwjlx(wjlx);
                    wj.setFcflj(cflj);
                    spcyQyWjjlService.updateById(wj);

                    LocalFileUploadUtils.deleteAbsFile(fileList.get(0));
                }

                return wj;
            }

            return null;
        }else {
            for (File file : fileList) {

                SpcyQyWjjl spcyQyWjjl = new SpcyQyWjjl();

                spcyQyWjjl.setFwjlx1(type);
                spcyQyWjjl.setFwjxsmc(fwjxsmc);

                String originalFilename = file.getName();
                // 文件类型
                String wjlx = originalFilename.substring(originalFilename.lastIndexOf("."));

                // 文件名
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));

                if (StringUtils.isBlank(spcyQyWjjl.getFwjxsmc())) {
                    spcyQyWjjl.setFwjxsmc(fileName);
                }

                String sjmc = GetUuIdUtils.ReplaceUuId();
                String wjccmc = sjmc + wjlx;
                String newDir = SpcyConstant.QY_Wjjl_File_Base_Url + "/" + DateConversionUtils.DateToMonthTwo(new Date());

                String cflj = "/" + newDir + "/" + wjccmc;
                boolean uploadFlag = spcyMinioUtils.putFlagFile(cflj, file, wjlx);

                String Id = GetUuIdUtils.NotReplaceUuId();
                spcyQyWjjl.setId(Id);
                spcyQyWjjl.setFpid(fpid);
                spcyQyWjjl.setFwjlx(wjlx);
                spcyQyWjjl.setFwjccmc(wjccmc);
                spcyQyWjjl.setFcflj(cflj);
                spcyQyWjjl.setFwjlx5(fwjlx5);
                spcyQyWjjl.setFwjlx6(fwjlx6);

                if (uploadFlag) {
                    boolean save = spcyQyWjjlService.save(spcyQyWjjl);
                    if (save) {
                        String czContent = "上传企业文件: ";
                        czContent += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(spcyQyWjjl));
                        spcyLogService.addLogs(LogConstant.LOGS_QY_INFO, czContent, fpid, SpcyConstant.LOGS_SYS_TYPE_BC, SpcyConstant.LOGS_SYS_TYPE_BC);
                    }

                    LocalFileUploadUtils.deleteAbsFile(file);

                    return spcyQyWjjl;
                }
            }
        }

        return null;
    }

    /**
     * 下载文件
     * @param fileId 文件id
     * @param response
     */
    public void getCrossLocalFile(String fileId, HttpServletResponse response) {
        if (StringUtils.isEmpty(fileId)){
            log.error("文件记录id为空");
            return;
        }
        SpcyQyWjjl wjjl = spcyQyWjjlService.getById(fileId);
        if (wjjl == null){
            log.error("文件记录id为-{}的文件记录不存在",fileId);
            return;
        }
        localFileUploadUtils.ejzLocalFileURlByZdy(wjjl.getFcflj(),businessConstant.isEnableQywjMinio,response);
    }

    /**
     * 删除文件
     * @param fileId 文件id
     * @return
     */
    public HttpResult deleteFileById(String fileId){
        if (StringUtils.isBlank(fileId)){
            return HttpResult.error("文件记录id不能为空");
        }
        SpcyQyWjjl wjjl = spcyQyWjjlService.getById(fileId);
        if (wjjl == null){
            return HttpResult.error("删除失败，文件记录id为-{}的文件记录不存在"+fileId+"");
        }

        String fpid = wjjl.getFpid(); // 业务id
        String wjlj = wjjl.getFcflj(); // 文件路径
        String log = "删除企业文件：";
        log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(wjjl));

        boolean flag = spcyQyWjjlService.removeById(fileId);
        if (flag) {
            if (StringUtils.isNotBlank(wjlj)) {
                localFileUploadUtils.deleteLocalFileUrlByZdy(wjlj,businessConstant.isEnableQywjMinio);
            }
            spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,fpid,SpcyConstant.LOGS_SYS_TYPE_TH,SpcyConstant.LOGS_SYS_TYPE_SC);
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 删除业务文件
     */
    public Result deleteInfoFileByFpid(String fpid){
        List<SpcyQyWjjl> wjjlList = spcyQyWjjlService.list(new LambdaQueryWrapper<SpcyQyWjjl>().eq(SpcyQyWjjl::getFpid, fpid));
        if (CollectionUtils.isNotEmpty(wjjlList)){
            for (SpcyQyWjjl wjjl : wjjlList) {
                String log = "删除企业相关文件：";
                boolean flag = spcyQyWjjlService.removeById(wjjl.getId());
                if (flag) {
                    if (StringUtils.isNotBlank(wjjl.getFcflj())) {
                        localFileUploadUtils.deleteLocalFileUrlByZdy(wjjl.getFcflj(),businessConstant.isEnableQywjMinio);
                    }
                    log += LogUtils.MapToStringMethod(ObjectToMapUtils.objectToMap(wjjl));
                    spcyLogService.addLogs(LogConstant.LOGS_QY_INFO,log,fpid,"删除企业信息附件",SpcyConstant.LOGS_SYS_TYPE_SC);
                }
                log = "";
            }
        }

        return Result.ok("删除成功");
    }

    /**
     * 获取对应的文件目录
     * @param fpid 业务id
     * @param type 设备确认信息/原料供应商审计/清洁验证/工艺验证/检查信息
     * @return
     */
    public List<Map> queryWjljByWjml(String fpid, String type){

        List<Map> reusltMapList = new ArrayList<>();
        List<SpcyQyWjjl> wjjlList = new ArrayList<>();
        // 获取申请事项文件记录
        boolean isExistsWjjl = true;
        if (StringUtils.isNotBlank(fpid)) {
            wjjlList = spcyQyWjjlService.list(new LambdaQueryWrapper<SpcyQyWjjl>()
                    .eq(SpcyQyWjjl::getFpid, fpid)
                    .orderByAsc(SpcyQyWjjl::getCreateTime));
            if (CollectionUtils.isEmpty(wjjlList)) {
                isExistsWjjl = false;
            }
        }else {
            isExistsWjjl = false;
        }

        // 文件目录
        List<SpcyQyWjml> wjmlList = spcyQyWjmlService.list(new LambdaQueryWrapper<SpcyQyWjml>()
                .eq(StringUtils.isNotBlank(type),SpcyQyWjml::getFwjlx1, type)
                .orderByAsc(SpcyQyWjml::getForder)
                .orderByAsc(SpcyQyWjml::getCreateTime));

        if (CollectionUtils.isNotEmpty(wjmlList)){
            Map resultMap = null;
            List<SpcyQyWjjl> wjjlFilterList = new ArrayList<>();
            for (SpcyQyWjml wjml : wjmlList){
                resultMap = new HashMap();
                resultMap.put("wjml", wjml.getFlxmc());

                // 存在文件记录
                if (isExistsWjjl) {
                    wjjlFilterList = wjjlList.stream()
                            .filter(f -> StringUtils.isNotBlank(f.getFwjlx1())
                                    && f.getFwjlx1().equals(wjml.getFlxmc())).collect(Collectors.toList());
                }
                resultMap.put("wjList", wjjlFilterList);

                reusltMapList.add(resultMap);
            }
        }


        return reusltMapList;
    }

    /**
     * 质量管理体系文件 - 文件记录
     * @param type 质量管理体系文件 | 抽检不合格信息文件 | 不良反应信息文件
     */
    public HttpResult queryWjljByType(String fpid,String type,Integer pageNo,Integer pageSize){
        if (StringUtils.isBlank(fpid)){
            return HttpResult.error("企业参数为空");
        }
        if (StringUtils.isBlank(type)){
            return HttpResult.error("文件参数为空");
        }
        Page<SpcyQyWjjl> page = new Page<>(pageNo, pageSize);
        IPage<SpcyQyWjjl> wjjlList = spcyQyWjjlService.page(page,new LambdaQueryWrapper<SpcyQyWjjl>()
                .eq(SpcyQyWjjl::getFpid, fpid)
                .eq(SpcyQyWjjl::getFwjlx1,type)
                .orderByDesc(SpcyQyWjjl::getCreateTime));

        return HttpResult.ok(wjjlList);
    }

    /**
     * 获取企业的所有附件
     * @param fqyid
     * @return
     */
    public HttpResult queryQyInfoAllFj(String fqyid){
        List<YcSysUser> userList = sysUserService.list(new LambdaQueryWrapper<YcSysUser>()
                .eq(YcSysUser::getFqyid, fqyid));
        String username = "";
        if (CollectionUtil.isNotEmpty(userList)){
            username = userList.get(0).getUsername();
        }

        List<Map> resultList = new ArrayList<>();
        List<SpcyQyWjml> allMlList = spcyQyWjmlService.list(new LambdaQueryWrapper<SpcyQyWjml>()
                .orderByAsc(SpcyQyWjml::getFwjlx1)
                .orderByAsc(SpcyQyWjml::getForder));

        List<SpcyQyWjjl> allFjList = spcyQyWjjlService.list(new LambdaQueryWrapper<SpcyQyWjjl>()
                .eq(SpcyQyWjjl::getCreateBy, username)
                .orderByAsc(SpcyQyWjjl::getCreateTime));
        if (CollectionUtil.isNotEmpty(allMlList)){
            List<String> mlList = allMlList.stream()
                    .map(SpcyQyWjml::getFlxmc)
                    .distinct()
                    .collect(Collectors.toList());
            Map result = null;
            for (String ml : mlList){
                result = new HashMap();
                result.put("ml", ml);

                List<SpcyQyWjjl> fjList = new ArrayList<>();
                if (CollectionUtil.isNotEmpty(allFjList)){
                    fjList = allFjList.stream()
                            .filter(f -> StringUtils.isNotBlank(f.getFwjlx1()) && f.getFwjlx1().equals(ml))
                            .collect(Collectors.toList());
                }
                result.put("fjList", fjList);
                resultList.add(result);
            }
        }

        return HttpResult.ok(resultList);
    }

    /**
     * 文件记录
     */
    public List<SpcyQyWjjl> selectCommonWjjl(String fpzid, String type){
        return spcyQyWjjlService.list(new LambdaQueryWrapper<SpcyQyWjjl>()
                .eq(SpcyQyWjjl::getFpid, fpzid)
                .eq(SpcyQyWjjl::getFwjlx1, type)
                .orderByAsc(SpcyQyWjjl::getCreateTime));
    }

    /**
     * 文件记录复制
     */
    public Result copyWjjl(String id){
        if (StringUtils.isBlank(id)){
            return Result.error("参数为空！");
        }

        SpcyQyWjjl wjjl = spcyQyWjjlService.getById(id);
        if (wjjl == null){
            return Result.error("没有相匹配的数据！");
        }
        SpcyQyWjjl newWjjl = new SpcyQyWjjl();
        BeanUtil.copyProperties(wjjl, newWjjl);
        newWjjl.setId(GetUuIdUtils.ReplaceUuId());
        newWjjl.setFwjlx("");
        newWjjl.setFcflj("");
        newWjjl.setFwjccmc("");
        newWjjl.setCreateTime(new Date());
        newWjjl.setUpdateTime(new Date());
        spcyQyWjjlService.save(newWjjl);

        return Result.ok();
    }

    /** 更新文件信息 */
    public HttpResult updateWj(SpcyQyWjjl reqVo){
        if (StringUtils.isNotBlank(reqVo.getId())){
            return HttpResult.error("参数为空！");
        }

        if (StringUtils.isNotBlank(reqVo.getFwjxsmc())){
            String validFileName = StringPatternUtils.isValidFileName(reqVo.getFwjxsmc());
            if (StringUtils.isNotBlank(validFileName)){
                return HttpResult.error("附件名称不能存在特殊字符："+validFileName);
            }
        }

        LambdaUpdateWrapper<SpcyQyWjjl> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcyQyWjjl::getId, reqVo.getId());

        SpcyQyWjjl updateBean = new SpcyQyWjjl();
        updateBean.setFwjxsmc(reqVo.getFwjxsmc());
        updateBean.setFwjlx5(reqVo.getFwjlx5());
        updateBean.setFwjlx6(reqVo.getFwjlx6());
        spcyQyWjjlService.update(updateBean, updateWrapper);

        return HttpResult.ok();
    }

}
